/** * Prepares the sets view. * * @return void */ public function setsAction() { // Get the available OAI-PMH to Omeka maps, which should correspond to // OAI-PMH metadata formats. $maps = $this->_getMaps(); $waitTime = oaipmh_harvester_config('requestThrottleSecs', 5); if ($waitTime) { $request = new OaipmhHarvester_Request_Throttler(new OaipmhHarvester_Request($this->_getParam('base_url')), array('wait' => $waitTime)); } else { $request = new OaipmhHarvester_Request($this->_getParam('base_url')); } // Catch errors such as "String could not be parsed as XML" $extraMsg = 'Please check to be certain the URL is correctly formatted ' . 'for OAI-PMH harvesting.'; try { $metadataFormats = $request->listMetadataFormats(); } catch (Zend_Uri_Exception $e) { $errorMsg = "Invalid URL given. {$extraMsg}"; } catch (Zend_Http_Client_Exception $e) { $errorMsg = $e->getMessage() . " {$extraMsg}"; } catch (OaipmhHarvester_Request_ThrottlerException $e) { $errorMsg = $e->getMessage(); } if (isset($errorMsg)) { $this->_helper->flashMessenger($errorMsg, 'error'); return $this->_helper->redirector->goto('index'); } /* Compare the available OAI-PMH metadataFormats with the available Omeka maps and extract only those that are common to both. The comparison is made between the metadata schemata, not the prefixes. */ $availableMaps = array_intersect($maps, $metadataFormats); // For a data provider that uses a resumption token for sets, see: // http://www.ajol.info/oai/ $response = $request->listSets($this->_getParam('resumption_token')); // Set the variables to the view object. $this->view->availableMaps = array_combine(array_keys($availableMaps), array_keys($availableMaps)); $this->view->sets = $response['sets']; $this->view->resumptionToken = array_key_exists('resumptionToken', $response) ? $response['resumptionToken'] : false; $this->view->baseUrl = $this->_getParam('base_url'); // Watch out for injection! $this->view->maps = $maps; }
public function perform() { if ($memoryLimit = oaipmh_harvester_config('memoryLimit')) { ini_set('memory_limit', $memoryLimit); } // Set the set. $harvest = $this->_db->getTable('OaipmhHarvester_Harvest')->find($this->_harvestId); if (!$harvest) { throw new UnexpectedValueException("Harvest with id = '{$this->_harvestId}' does not exist."); } // Resent jobs can remain queued after all the items themselves have // been deleted. Skip if that's the case. if ($harvest->status == OaipmhHarvester_Harvest::STATUS_DELETED) { _log("Queued harvest with ID = {$harvest->id} was deleted prior " . "to running this job."); return; } require_once 'OaipmhHarvester/Harvest/Abstract.php'; $harvester = OaipmhHarvester_Harvest_Abstract::factory($harvest); $harvester->harvest(); if ($harvest->isResumable() && !$harvest->isError()) { $this->resend(); } }