/** * 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); } }
/** * 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'; } }
/** * 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(); }
<?php } else { ?> <ListRecords> <?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>
/** * 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'; } }
<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>