diff --git a/module/finc/src/finc/RecordDriver/SolrAI.php b/module/finc/src/finc/RecordDriver/SolrAI.php index 0e65b260be43deaaef526a4a80081f90af351868..07c22e4f8a5e682e1d23426030bfbdc1dc20e625 100644 --- a/module/finc/src/finc/RecordDriver/SolrAI.php +++ b/module/finc/src/finc/RecordDriver/SolrAI.php @@ -28,8 +28,8 @@ * @link http://vufind.org/wiki/vufind2:record_drivers Wiki */ namespace finc\RecordDriver; -use \VuFindHttp\HttpServiceAwareInterface as HttpServiceAwareInterface; -use ZendService\ReCaptcha\Exception; +use \VuFindHttp\HttpServiceAwareInterface as HttpServiceAwareInterface, + Zend\Log\LoggerAwareInterface as LoggerAwareInterface; /** * Recorddriver for Solr records from the aggregated index of Leipzig University @@ -44,9 +44,10 @@ use ZendService\ReCaptcha\Exception; * @SuppressWarnings(PHPMD.ExcessivePublicCount) */ class SolrAI extends SolrDefault implements - HttpServiceAwareInterface + HttpServiceAwareInterface, LoggerAwareInterface { use \VuFindHttp\HttpServiceAwareTrait; + use \VuFind\Log\LoggerAwareTrait; /** * AI record diff --git a/module/finc/src/finc/RecordDriver/SolrMarcRemote.php b/module/finc/src/finc/RecordDriver/SolrMarcRemote.php index 93efb36a2e974ab92f229e52ce09cf217e8fdbfb..fce2858ef88d61314799c20e058d285a10fccbd5 100644 --- a/module/finc/src/finc/RecordDriver/SolrMarcRemote.php +++ b/module/finc/src/finc/RecordDriver/SolrMarcRemote.php @@ -29,7 +29,8 @@ * @link http://vufind.org/wiki/vufind2:record_drivers Wiki */ namespace finc\RecordDriver; -use \Zend\Log\LoggerInterface; +use VuFindHttp\HttpServiceAwareInterface as HttpServiceAwareInterface, + Zend\Log\LoggerAwareInterface as LoggerAwareInterface; /** * Model for MARC records without a fullrecord in Solr. The fullrecord is being @@ -43,14 +44,11 @@ use \Zend\Log\LoggerInterface; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/vufind2:record_drivers Wiki */ -class SolrMarcRemote extends SolrMarc +class SolrMarcRemote extends SolrMarc implements + HttpServiceAwareInterface, LoggerAwareInterface { - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; + use \VuFindHttp\HttpServiceAwareTrait; + use \VuFind\Log\LoggerAwareTrait; /** * MARC record @@ -143,40 +141,28 @@ class SolrMarcRemote extends SolrMarc throw new \Exception('empty id given'); } - if (!$this->uriPattern) { + if (empty($this->uriPattern)) { throw new \Exception('no Marc-Server configured'); } - $parsed_url = parse_url($this->uriPattern); - - if (false === isset($config['options']) || false === is_array($config['options'])) { - $config['options']['timeout'] = 0.1; - } - - $options = [$parsed_url['scheme'] => $config['options']]; - $streamContext = stream_context_create($options); - $url = sprintf($this->uriPattern, $id); - $loopCount = 0; - - for ($loopCount=0; $loopCount<10;$loopCount++) { - $content = @file_get_contents($url , false, $streamContext); + try { + $response = $this->httpService->get($url); + } catch (\Exception $e) { + throw new Exception($e->getMessage()); + } - if (false === $content) { - $this->debug('Unable to fetch marc from server ' . $url); - continue; - } else if (empty($content)) { - $this->debug('content is empty, trying again. If this happens very often, try to increase timeout'); - continue; - } + if (!$response->isSuccess()) { + $this->debug( + 'HTTP status ' . $response->getStatusCode() . + ' received, retrieving data for record: ' . $id + ); - return $content; + return false; } - $this->debug('tried too many times. aborting at record ' . $id); - return false; - + return $response->getBody(); } /** @@ -244,32 +230,6 @@ class SolrMarcRemote extends SolrMarc return (isset($this->fields[$string]) ? $this->fields[$string] : ''); } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug(get_class($this) . ": $msg"); - } - } - /** * Return an array of associative URL arrays with one or more of the following * keys: