public function testRecordExists() { $record = new OaipmhHarvester_Record(); $item = insert_item(array('public' => true)); $harvest = new OaipmhHarvester_Harvest(); $record->item_id = $item->id; $record->identifier = 'foo-bar'; $record->datestamp = '2010-04-28'; $harvest->base_url = 'http://example.com'; $harvest->metadata_prefix = 'oai_dc'; $harvest->status = OaipmhHarvester_Harvest::STATUS_COMPLETED; $request = new OaipmhHarvester_Request_Mock(); $xmlFile = dirname(__FILE__) . '/_files/ListRecords.xml'; $request->setResponseXml(file_get_contents($xmlFile)); $harvest->setRequest($request); $harvest->save(); $record->harvest_id = $harvest->id; $record->save(); $harvester = new OaipmhHarvester_Harvest_OaiDc($harvest); $harvester->harvest(); $item = $this->db->getTable('Item')->find($record->item_id); $this->assertEquals("Record Title", metadata($item, array('Dublin Core', 'Title'))); }
/** * Launch the harvest process. * * @return void */ public function harvestAction() { // Only set on re-harvest $harvest_id = $this->_getParam('harvest_id'); // If true, this is a re-harvest, all parameters will be the same if ($harvest_id) { $harvest = $this->_helper->db->getTable('OaipmhHarvester_Harvest')->find($harvest_id); // Set vars for flash message $setSpec = $harvest->set_spec; $baseUrl = $harvest->base_url; $metadataPrefix = $harvest->metadata_prefix; // Only on successfully-completed harvests: use date-selective // harvesting to limit results. if ($harvest->status == OaipmhHarvester_Harvest::STATUS_COMPLETED) { $harvest->start_from = $harvest->initiated; } else { $harvest->start_from = null; } } else { $baseUrl = $this->_getParam('base_url'); $metadataSpec = $this->_getParam('metadata_spec'); $setSpec = $this->_getParam('set_spec'); $setName = $this->_getParam('set_name'); $setDescription = $this->_getParam('set_description'); $metadataPrefix = $metadataSpec; $harvest = $this->_helper->db->getTable('OaipmhHarvester_Harvest')->findUniqueHarvest($baseUrl, $setSpec, $metadataPrefix); if (!$harvest) { // There is no existing identical harvest, create a new entry. $harvest = new OaipmhHarvester_Harvest(); $harvest->base_url = $baseUrl; $harvest->set_spec = $setSpec; $harvest->set_name = $setName; $harvest->set_description = $setDescription; $harvest->metadata_prefix = $metadataPrefix; } } // Insert the harvest. $harvest->status = OaipmhHarvester_Harvest::STATUS_QUEUED; $harvest->initiated = date('Y:m:d H:i:s'); $harvest->save(); $jobDispatcher = Zend_Registry::get('bootstrap')->getResource('jobs'); $jobDispatcher->setQueueName('imports'); try { $jobDispatcher->sendLongRunning('OaipmhHarvester_Job', array('harvestId' => $harvest->id)); } catch (Exception $e) { $harvest->status = OaipmhHarvester_Harvest::STATUS_ERROR; $harvest->addStatusMessage(get_class($e) . ': ' . $e->getMessage(), OaipmhHarvester_Harvest_Abstract::MESSAGE_CODE_ERROR); throw $e; } if ($setSpec) { $message = "Set \"{$setSpec}\" is being harvested using \"{$metadataPrefix}\". This may take a while. Please check below for status."; } else { $message = "Repository \"{$baseUrl}\" is being harvested using \"{$metadataPrefix}\". This may take a while. Please check below for status."; } if ($harvest->start_from) { $message = $message . " Harvesting is continued from {$harvest->start_from} ."; } $this->_helper->flashMessenger($message, 'success'); return $this->_helper->redirector->goto('index'); }
/** * The post process is the import process (harvesting) if set. * * @internal This process should be managed as a job. * * @see OaipmhHarvester_IndexController::harvestAction() * * @param OaiPmhStaticRepository $folder */ private function _postProcess() { if (plugin_is_active('OaiPmhGateway') && $this->getParameter('oaipmh_gateway')) { $gateway = $this->getGateway(); if (empty($gateway)) { $gateway = new OaiPmhGateway(); $gateway->url = $this->getStaticRepositoryUrl(); $gateway->public = false; $gateway->save(); } if (plugin_is_active('OaipmhHarvester') && $this->getParameter('oaipmh_harvest')) { $prefix = $this->getParameter('oaipmh_harvest_prefix'); $updateMetadata = $this->getParameter('oaipmh_harvest_update_metadata'); $updateFiles = $this->getParameter('oaipmh_harvest_update_files'); $harvest = $gateway->getHarvest($prefix); if (empty($harvest)) { $harvest = new OaipmhHarvester_Harvest(); $harvest->base_url = $gateway->getBaseUrl(); $harvest->metadata_prefix = $prefix; } // The options are always updated. $harvest->update_metadata = $updateMetadata ?: OaipmhHarvester_Harvest::UPDATE_METADATA_ELEMENT; $harvest->update_files = $updateFiles ?: OaipmhHarvester_Harvest::UPDATE_FILES_FULL; $message = __('Harvester launched.'); $this->addMessage($message, OaiPmhStaticRepository::MESSAGE_CODE_NOTICE); _log('[OaiPmhStaticRepository] ' . __('Folder #%d [%s]: %s', $this->id, $this->uri, $message)); // Insert the harvest. $harvest->status = OaipmhHarvester_Harvest::STATUS_QUEUED; $harvest->initiated = date('Y:m:d H:i:s'); $harvest->save(); $jobDispatcher = Zend_Registry::get('bootstrap')->getResource('jobs'); $jobDispatcher->setQueueName('imports'); try { $jobDispatcher->sendLongRunning('OaipmhHarvester_Job', array('harvestId' => $harvest->id)); } catch (Exception $e) { $message = __('Harvester crashed: %s', get_class($e) . ': ' . $e->getMessage()); $this->addMessage($message, OaiPmhStaticRepository::MESSAGE_CODE_NOTICE); _log('[OaiPmhStaticRepository] ' . __('Folder #%d [%s]: %s', $this->id, $this->uri, $message), Zend_Log::ERR); $harvest->status = OaipmhHarvester_Harvest::STATUS_ERROR; $harvest->save(); $this->addMessage(get_class($e) . ': ' . $e->getMessage(), OaipmhHarvester_Harvest_Abstract::MESSAGE_CODE_ERROR); } } // TODO For remote archive folders, upload the xml file to them. } }