コード例 #1
0
ファイル: oai-harvester.php プロジェクト: stweil/OA-Statistik
 /**
  * Controls the actual harvesting
  */
 function harvest()
 {
     $oaisp = new OAIServiceProvider($this->config['oai_server'], $this->logger);
     try {
         $params = array('metadataPrefix' => $this->config['metadataPrefix']);
         if (!@$this->config['full_harvest']) {
             $params['from'] = $this->get_last_datestamp();
         }
         $oaisp->query_listrecords(array($this, 'record_reader'), $params);
     } catch (OAIServiceProviderOAIErrorNoRecordsMatchException $e) {
         $this->log('no new records.');
     }
 }
 public function executeHarvest(sfWebRequest $request)
 {
     if ($request->hasParameter('ids')) {
         $data_providers = oaiDataProviderPeer::retrieveByPKs($request->getParameter('ids'));
     } else {
         if ($request->hasParameter('id')) {
             $data_providers = array(oaiDataProviderPeer::retrieveByPK($request->getParameter('id')));
         } else {
             $data_providers = oaiDataProviderPeer::retrieveEnabled();
         }
     }
     $service_provider = new OAIServiceProvider($data_providers);
     if ($service_provider->canHarvest() && $service_provider->harvest()) {
         $updates = $service_provider->getNbUpdates();
         if ($updates > 0) {
             $notice = 'Successfully harvested ' . $updates . ' records.';
         } else {
             $notice = 'No new records to harvest. Everything is up to date.';
         }
         $this->getUser()->setFlash('notice', $notice);
         $errors = $service_provider->getErrors();
         if (count($errors) > 0) {
             $error = 'Some errors have been found while harvesting: ';
             foreach ($errors as $url => $specific_errors) {
                 $error .= sprintf('%s (%s). ', implode(', ', $specific_errors), $url);
             }
             $this->getUser()->setFlash('error', $error);
         }
     } else {
         $errors = $service_provider->getErrors();
         if (count($errors) > 0) {
             $error = 'Unable to complete harvesting. Too many errors have been found while trying to do so: ';
             foreach ($errors as $url => $specific_errors) {
                 $error .= sprintf('%s (%s). ', implode(', ', $specific_errors), $url);
             }
             $this->getUser()->setFlash('error', $error);
         }
     }
     $this->redirect('@oai_data_provider');
 }
コード例 #3
0
 function __test($server_url)
 {
     try {
         $oaisp = new OAIServiceProvider($server_url);
         $oaisp->query_identify(array($oaisp, '__test_xml_dump'));
         //$oaisp->query_listsets(array($oaisp,'__test_xml_dump'));
         $oaisp->query_listmetadataformats(array($oaisp, '__test_xml_dump'));
         $oaisp->query_listidentifiers(array($oaisp, '__test_xml_dump'), array('metadataPrefix' => 'oas'));
         $oaisp->query_listrecords(array($oaisp, '__test_xml_dump'), array('metadataPrefix' => 'oas'));
     } catch (Exception $e) {
         echo "Error:\n";
         var_dump($e);
     }
 }