diff --git a/module/VuFind/src/VuFind/Harvester/OAI.php b/module/VuFind/src/VuFind/Harvester/OAI.php index 86363f87ace54dfd4a649347e78060209c178b4b..2564a0c8d0143e381b0b0886a65a34a60922891d 100644 --- a/module/VuFind/src/VuFind/Harvester/OAI.php +++ b/module/VuFind/src/VuFind/Harvester/OAI.php @@ -26,7 +26,7 @@ * @link http://vufind.org/wiki/importing_records#oai-pmh_harvesting Wiki */ namespace VuFind\Harvester; -use VuFind\Http\Client, Zend\Console\Console; +use Zend\Console\Console; /** * OAI Class @@ -41,12 +41,20 @@ use VuFind\Http\Client, Zend\Console\Console; */ class OAI { + /** + * HTTP client + * + * @var \Zend\Http\Client + */ + protected $client; + /** * URL to harvest from * * @var string */ protected $baseURL; + /** * Target set to harvest (null for all records) * @@ -177,11 +185,15 @@ class OAI /** * Constructor. * - * @param string $target Target directory for harvest. - * @param array $settings OAI-PMH settings from oai.ini. + * @param string $target Target directory for harvest. + * @param array $settings OAI-PMH settings from oai.ini. + * @param \Zend\Http\Client $client HTTP client */ - public function __construct($target, $settings) + public function __construct($target, $settings, \Zend\Http\Client $client) { + // Store client: + $this->client = $client; + // Don't time out during harvest!! set_time_limit(0); @@ -371,20 +383,20 @@ class OAI // Set up retry loop: while (true) { // Set up the request: - $request = new Client( - null, array('timeout' => 60) // TODO: make timeout configurable - ); - $request->setUri($this->baseURL); + $this->client->resetParameters(); + $this->client->setUri($this->baseURL); + // TODO: make timeout configurable + $this->client->setOptions(array('timeout' => 60)); // Load request parameters: - $query = $request->getRequest()->getQuery(); + $query = $this->client->getRequest()->getQuery(); $query->set('verb', $verb); foreach ($params as $key => $value) { $query->set($key, $value); } // Perform request and die on error: - $result = $request->setMethod('GET')->send(); + $result = $this->client->setMethod('GET')->send(); if ($result->getStatusCode() == 503) { $delayHeader = $result->getHeaders()->get('Retry-After'); $delay = is_object($delayHeader) diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/HarvestController.php b/module/VuFindConsole/src/VuFindConsole/Controller/HarvestController.php index 36bb87353ad4cea373a0347d04d44889ae6e9200..29eee5f038d87a9dec7b516594069a05e3013e72 100644 --- a/module/VuFindConsole/src/VuFindConsole/Controller/HarvestController.php +++ b/module/VuFindConsole/src/VuFindConsole/Controller/HarvestController.php @@ -102,7 +102,9 @@ class HarvestController extends AbstractBase if (!empty($target) && !empty($settings)) { Console::writeLine("Processing {$target}..."); try { - $harvest = new OAI($target, $settings); + $client = $this->getServiceLocator()->get('VuFind\Http') + ->createClient(); + $harvest = new OAI($target, $settings, $client); $harvest->launch(); } catch (\Exception $e) { Console::writeLine($e->getMessage());