/** * 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. } }
public function harvestAction() { $folder = $this->_db->findById(); if (empty($folder)) { $message = __('Folder #%d does not exist.', $this->_getParam('id')); $this->_helper->flashMessenger($message, 'error'); return $this->forward('browse'); } if (!plugin_is_active('OaiPmhGateway')) { $message = __('The folder cannot be harvested: the plugin OAI-PMH Gateway is not enabled.'); $this->_helper->flashMessenger($message, 'error'); return $this->forward('browse'); } if (!plugin_is_active('OaipmhHarvester')) { $message = __('The folder cannot be harvested: the plugin OAI-PMH Harvester is not enabled.'); $this->_helper->flashMessenger($message, 'error'); return $this->forward('browse'); } $folder->setParameter('oaipmh_gateway', true); $folder->setParameter('oaipmh_harvest', true); $folder->save(); // Get or create the gateway. $gateway = $folder->getGateway(); if (empty($gateway)) { $gateway = new OaiPmhGateway(); $gateway->url = $folder->getStaticRepositoryUrl(); $gateway->public = false; $gateway->save(); } $options = array(); $options['update_metadata'] = $folder->getParameter('oaipmh_harvest_update_metadata'); $options['update_files'] = $folder->getParameter('oaipmh_harvest_update_files'); $harvest = $gateway->harvest($folder->getParameter('oaipmh_harvest_prefix'), $options); // No harvest and no prefix, so go to select page. if ($harvest === false) { $message = __('A metadata prefix should be selected to harvest the repository "%s".', $gateway->url); $this->_helper->flashMessenger($message, 'success'); $url = absolute_url(array('module' => 'oaipmh-harvester', 'controller' => 'index', 'action' => 'sets'), null, array('base_url' => $gateway->url)); $this->redirect($url); } elseif (is_null($harvest)) { $message = __('The repository "%s" cannot be harvested.', $gateway->url) . ' ' . __('Check the gateway.'); $this->_helper->flashMessenger($message, 'error'); $url = absolute_url(array('module' => 'oai-pmh-gateway', 'controller' => 'index', 'action' => 'browse'), null, array('id' => $gateway->id)); $this->redirect($url); } // Else the harvest is launched. $message = __('The harvest of the folder "%" is launched.', $gateway->url); $this->_helper->flashMessenger($message, 'success'); $this->forward('browse'); }