コード例 #1
0
 /**
  * Mail error report
  *
  * @param string $msg an error message
  * @return bool true for message sent properly
  */
 public static function mailErrors($msg)
 {
     $to = QubitOai::getAdminEmail();
     $from = $to;
     $subject = 'Qubit OAI-PMH Harvest';
     $message = $msg;
     $headers = "From: {QubitOai::getAdminEmail()}\r\nX-Mailer: PHP/" . phpversion();
     $params = sprintf('-oi -f %s', $from);
     return mail($to, $subject, $message, $headers, $params);
 }
コード例 #2
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     $request->setRequestFormat('xml');
     $this->date = QubitOai::getDate();
     $this->path = $this->request->getUriPrefix() . $this->request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
     $this->sets = array();
     foreach (QubitInformationObject::getCollections() as $el) {
         $this->sets[] = new sfIsadPlugin($el);
     }
 }
コード例 #3
0
 public function execute($request)
 {
     $this->requestname = $request;
     $request->setRequestFormat('xml');
     $this->date = gmdate('Y-m-d\\TH:i:s\\Z');
     $this->attributes = $request->getGetParameters();
     /*
      * If limit dates are not supplied, define them as ''
      */
     if (!isset($request->from)) {
         $this->from = '';
     } else {
         $this->from = $request->from;
     }
     if (!isset($request->until)) {
         $this->until = '';
     } else {
         $this->until = $request->until;
     }
     $this->collectionsTable = QubitOai::getCollectionArray();
     /*
      * If set is not supplied, define it as ''
      */
     if (!isset($request->set)) {
         $collection = '';
     } else {
         $collection = QubitOai::getCollectionInfo($request->set, $this->collectionsTable);
     }
     //Get the records according to the limit dates and collection
     $this->records = QubitInformationObject::getUpdatedRecords($this->from, $this->until, $collection);
     $this->publishedRecords = array();
     foreach ($this->records as $record) {
         if ($record->getPublicationStatus()->statusId == QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID) {
             $this->publishedRecords[] = $record;
         }
     }
     $this->recordsCount = count($this->publishedRecords);
     $this->path = $request->getUriPrefix() . $request->getPathInfo();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
 }
コード例 #4
0
 public function execute($request)
 {
     $request->setRequestFormat('xml');
     $oai_local_identifier_value = $request->identifier;
     //TODO: strip the trailing integer value from the full OAI Identifier to get the OaiLocalIdentifier
     $oai_local_identifier_id = QubitOai::getOaiIdNumber($oai_local_identifier_value);
     $this->informationObject = QubitInformationObject::getRecordByOaiID($oai_local_identifier_id);
     $request->setAttribute('informationObject', $this->informationObject);
     // just cut-and-paste from OaiIdentify action for now
     $this->date = gmdate('Y-m-d\\TH:i:s\\Z');
     $this->collectionsTable = QubitOai::getCollectionArray();
     $this->path = $request->getUriPrefix() . $request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
 }
コード例 #5
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     $request->setRequestFormat('xml');
     $this->date = QubitOai::getDate();
     $this->path = $this->request->getUriPrefix() . $this->request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
     $this->sets = array();
     foreach (QubitInformationObject::getCollections() as $el) {
         $this->sets[] = new sfIsadPlugin($el);
     }
     if (isset($this->request->verb)) {
         switch ($this->request->verb) {
             case 'Identify':
                 $this->verb = 'identify';
                 break;
             case 'ListMetadataFormats':
                 $this->verb = 'listMetadataFormats';
                 break;
             case 'ListSets':
                 $this->verb = 'listSets';
                 break;
             case 'ListRecords':
                 $this->verb = 'listRecords';
                 break;
             case 'ListIdentifiers':
                 $this->verb = 'listIdentifiers';
                 break;
             case 'GetRecord':
                 $this->verb = 'getRecord';
                 break;
             default:
                 $this->verb = 'badVerb';
         }
     } else {
         $this->verb = 'badVerb';
     }
 }
コード例 #6
0
 /**
  * Populate the OAI Repository form with database values (non-localized)
  */
 protected function populateOaiRepositoryForm()
 {
     // Get OAI Repository settings
     $oaiEnabled = QubitSetting::getSettingByName('oai_enabled');
     $oaiRepositoryCode = QubitSetting::getSettingByName('oai_repository_code');
     $oaiRepositoryIdentifier = QubitOai::getRepositoryIdentifier();
     $sampleOaiIdentifier = QubitOai::getSampleIdentifier();
     $resumptionTokenLimit = QubitSetting::getSettingByName('resumption_token_limit');
     // Set defaults for global form
     $this->oaiRepositoryForm->setDefaults(array('oai_enabled' => isset($oaiEnabled) ? intval($oaiEnabled->getValue(array('sourceCulture' => true))) : 1, 'oai_repository_code' => isset($oaiRepositoryCode) ? $oaiRepositoryCode->getValue(array('sourceCulture' => true)) : null, 'oai_repository_identifier' => $oaiRepositoryIdentifier, 'sample_oai_identifier' => $sampleOaiIdentifier, 'resumption_token_limit' => isset($resumptionTokenLimit) ? $resumptionTokenLimit->getValue(array('sourceCulture' => true)) : null));
 }
コード例 #7
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     //Set resumption token to null so that we enter in the harvester loop
     $resumptionToken = 1;
     //Set no records match to false to start with
     $this->noRecordsMatch = false;
     //Keep track of number of records harvested
     $this->recordCount = 0;
     //If the request did not go through the proper routing, forward to 404
     if (!isset($request->id)) {
         $this->forward404();
     }
     $harvestInfo = QubitOaiHarvest::getById($request->id);
     $harvestInfo->setLastHarvestAttempt(QubitOai::getDate());
     $harvestInfo->save();
     $rep = $harvestInfo->getOaiRepository();
     //If repository was not found 404
     if (!$rep) {
         $this->forward404();
     }
     $this->repositoryName = $rep->getName();
     //Initialise $oaiSimpleRes
     $verb = '';
     $oaiSimpleRes = array();
     $from = date('Y-m-d\\TH:i:s\\Z', strtotime($harvestInfo->getLastHarvest()));
     $until = gmdate('Y-m-d\\TH:i:s\\Z');
     //Create the base request
     $verb = 'verb=ListRecords';
     if ($harvestInfo->getLastHarvest() != null) {
         $verb .= '&from=' . $from;
     }
     $verb .= '&until=' . $until;
     $verb .= '&metadataPrefix=' . $harvestInfo->getMetadataPrefix();
     //Add the set parameter if supplied
     if ($harvestInfo->getSet() != null) {
         $verb .= '&set=' . $harvestInfo->getSet();
     }
     while ($resumptionToken) {
         //Load XML through simplexml http
         $oaiSimple = simplexml_load_file($rep->getUri() . '?' . $verb);
         //Strip oai header, construct array of records
         $oaiSimple->registerXPathNamespace('c', 'http://www.openarchives.org/OAI/2.0/');
         if ($oaiSimple->xpath('//c:error')) {
             $oaiReceivedError = $oaiSimple->xpath('//c:error');
             $oaiReceivedErrorAttr = $oaiReceivedError[0]->attributes();
             if ($oaiReceivedErrorAttr['code'] == 'noRecordsMatch') {
                 $this->noRecordsMatch = true;
             } else {
                 $this->forward404();
             }
         }
         if (!$this->noRecordsMatch) {
             //Container for xml import errors
             $this->errorsFound = array();
             $this->errorsXML = array();
             //Create header and footer for XML record for it to validate
             $oaiHeader = '<?xml version="1.0" encoding="UTF-8" ?>';
             $oaiFooter = '';
             $oaiRecords = $oaiSimple->xpath('//c:ListRecords/c:record');
             foreach ($oaiRecords as $oaiRec) {
                 $oaiRec = $oaiHeader . $oaiRec->asXML() . $oaiFooter . "\n";
                 $options = array();
                 $options = $options['strictXmlParsing'] = false;
                 $importer = new QubitXmlImport();
                 $importer->import($oaiRec, $options);
                 //          $importer = QubitXmlImport::execute($oaiRec, $options);
                 if ($importer->hasErrors()) {
                     $this->errorsFound[] = $importer->getErrors();
                     $this->errorsXML[] = $oaiRec;
                 }
             }
             // Increment record count to keep track of number of records harvested
             $this->recordCount += count($oaiRecords);
             $nbrErrors = count($this->errorsFound);
             $errorReport = '';
             $errorReportHTML = '';
             for ($i = 0; $i < $nbrErrors; $i++) {
                 $errorReport .= "Error when importing record:\n\n" . $this->errorsXML[$i] . "\n\nError message:\n" . $this->errorsFound[$i];
                 $errorReport .= "\n**************************************************\n\n";
                 $errorReportHTML .= "Error when importing record:\n\n <br>" . $this->errorsXML[$i] . "\n\n <br> Error message: <br> \n" . $this->errorsFound[$i];
             }
         }
         //Check for resumption token which will also be the while loop indicator
         $oaiResumptionToken = $oaiSimple->xpath('//c:ListRecords/c:resumptionToken');
         if ($oaiResumptionToken == false || count($oaiResumptionToken) > 1) {
             $resumptionToken = false;
         } else {
             $resumptionToken = $oaiResumptionToken[0];
             $verb = 'verb=ListRecords&resumptionToken=' . $resumptionToken;
         }
     }
     // Update last harvest date
     $harvestInfo->setLastHarvest($until);
     $harvestInfo->save();
 }
コード例 #8
0
?>
</earliestDatestamp>
    <deletedRecord><?php 
echo $deletedRecord;
?>
</deletedRecord>
    <granularity><?php 
echo $granularity;
?>
</granularity>
    <compression><?php 
echo $compression;
?>
</compression>
    <description>
      <oai-identifier xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai-identifier http://www.openarchives.org/OAI/2.0/oai-identifier.xsd">
        <scheme>oai</scheme>

        <repositoryIdentifier><?php 
echo QubitOai::getRepositoryIdentifier();
?>
</repositoryIdentifier>
        <delimiter>:</delimiter>
        <sampleIdentifier><?php 
echo QubitOai::getSampleIdentifier();
?>
</sampleIdentifier>
      </oai-identifier>
    </description>
  </Identify>
コード例 #9
0
<?php 
    foreach ($publishedRecords as $record) {
        $requestname->setAttribute('informationObject', $record);
        ?>
   <record>
    <header>
      <identifier><?php 
        echo $record->getOaiIdentifier();
        ?>
</identifier>
      <datestamp><?php 
        echo QubitOai::getDate($record->getUpdatedAt());
        ?>
</datestamp>
      <setSpec><?php 
        echo QubitOai::getSetSpec($record->getLft(), $collectionsTable);
        ?>
</setSpec>
    </header>
    <metadata>
      <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
          <?php 
        echo get_component('informationobject', 'dublinCoreElements');
        ?>
      </oai_dc:dc>
    </metadata>
   </record>
<?php 
    }
    ?>
  </ListRecords>
コード例 #10
0
  <ListMetadataFormats>
<?php 
foreach (QubitOai::getMetadataFormats() as $metadataFormat) {
    echo "    <metadataFormat>\n";
    echo "      <metadataPrefix>" . $metadataFormat['prefix'] . "</metadataPrefix>\n";
    echo "      <schema>" . $metadataFormat['schema'] . "</schema>\n";
    echo "      <metadataNamespace>" . $metadataFormat['namespace'] . "</metadataNamespace>\n";
    echo "    </metadataFormat>\n";
}
?>
  </ListMetadataFormats>
コード例 #11
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     // only respond to OAI requests if the feature has been enabled
     if (sfConfig::get('app_oai_oai_enabled') == 0) {
         // the following displays a GUI response, should we return a
         // '503 - Service unavailable' HTTP response (without specifying
         // a 'Retry-After' parameter instead?
         $this->forward('admin', 'oaiDisabled');
     }
     $request->setRequestFormat('xml');
     /*    print_r($this->oaiErrorArray);
         //Check for null and duplicate parameters
         if(QubitOai::hasDuplicateOrNullParameters())
         {
           $request->setParameter('errorCode', 'badArgument');
           $request->setParameter('errorMsg', $this->oaiErrorArray{'badArgument'});
           $this->forward('oai', 'error');
         }*/
     $this->date = QubitOai::getDate();
     $this->path = $this->request->getUriPrefix() . $this->request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
     $this->sets = array();
     foreach (QubitInformationObject::getCollections() as $el) {
         $this->sets[] = new sfIsadPlugin($el);
     }
     /**
      * Validate that verb is valid
      */
     if (isset($this->request->verb)) {
         if (!in_array($this->request->verb, $this->oaiVerbArr)) {
             $request->setParameter('errorCode', 'badVerb');
             $request->setParameter('errorMsg', 'Value of the verb argument is not a legal OAI-PMH verb, the verb argument is missing, or the verb argument is repeated.');
             $this->forward('oai', 'error');
         }
         /**
          * Validate that attributes are valid
          */
         $allowedKeys = sfConfig::get('mod_oai_' . $this->request->verb . 'Allowed');
         $mandatoryKeys = sfConfig::get('mod_oai_' . $this->request->verb . 'Mandatory');
         if (!QubitOai::checkBadArgument($this->attributesKeys, $allowedKeys, $mandatoryKeys)) {
             $request->setParameter('errorCode', 'badArgument');
             $request->setParameter('errorMsg', 'The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.');
             $this->forward('oai', 'error');
         }
         // For now, if there is a metadataPrefix requested other than oai_dc, fail the request
         $metadataPrefix = $this->request->metadataPrefix;
         if ($metadataPrefix != '' and $metadataPrefix != 'oai_dc') {
             $request->setParameter('errorCode', 'badVerb');
             $request->setParameter('errorMsg', 'The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.');
             $this->forward('oai', 'error');
         }
         switch ($this->request->verb) {
             case 'Identify':
                 $this->verb = 'identify';
                 break;
             case 'ListMetadataFormats':
                 $this->verb = 'listMetadataFormats';
                 break;
             case 'ListSets':
                 $this->verb = 'listSets';
                 break;
             case 'ListRecords':
                 $this->verb = 'listRecords';
                 break;
             case 'ListIdentifiers':
                 $this->verb = 'listIdentifiers';
                 break;
             case 'GetRecord':
                 $this->verb = 'getRecord';
                 break;
             default:
                 $this->verb = 'badVerb';
         }
     } else {
         $this->verb = 'badVerb';
     }
 }
コード例 #12
0
  <GetRecord>
   <record>
    <header>
      <identifier><?php 
echo $informationObject->getOaiIdentifier();
?>
</identifier>
      <datestamp><?php 
echo QubitOai::getDate($informationObject->getUpdatedAt());
?>
</datestamp>
      <setSpec><?php 
echo QubitOai::getSetSpec($informationObject->getLft(), $collectionsTable);
?>
</setSpec>
    </header>
    <metadata>
      <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
          <?php 
echo get_component('informationobject', 'dublinCoreElements');
?>
      </oai_dc:dc>
    </metadata>
  </record>
 </GetRecord>