Beispiel #1
0
 /**
  * make sure documents related to Collection[Role|]s in subtree are updated 
  * (XML-Cache and server_date_published)
  *
  * @param Opus_Collection Starting point for recursive update to documents
  */
 protected function updateDocuments($model)
 {
     if (is_null($model) || is_null($model->getId())) {
         // TODO explain why this is right
         return;
     }
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $collectionIdSelect = $collections->selectSubtreeById($model->getId(), 'id');
     $documentFinder = new Opus_DocumentFinder();
     $documentFinder->setCollectionId($collectionIdSelect);
     // clear affected documents from cache
     $xmlCache = new Opus_Model_Xml_Cache();
     $xmlCache->removeAllEntriesWhereSubSelect($documentFinder->getSelectIds());
     // update ServerDateModified for affected documents
     $date = new Opus_Date();
     $date->setNow();
     Opus_Document::setServerDateModifiedByIds($date, $documentFinder->ids());
 }
 /**
  * Retrieve all document ids for a valid oai request.
  *
  * @param array &$oaiRequest
  * @return array
  */
 public function query(array $oaiRequest)
 {
     $finder = new Opus_DocumentFinder();
     // add server state restrictions
     $finder->setServerStateInList($this->deliveringDocumentStates);
     $metadataPrefix = $oaiRequest['metadataPrefix'];
     if ('xMetaDissPlus' === $metadataPrefix || 'xMetaDiss' === $metadataPrefix) {
         $finder->setFilesVisibleInOai();
     }
     if ('xMetaDiss' === $metadataPrefix) {
         $finder->setTypeInList($this->xMetaDissRestriction);
     }
     if ('epicur' === $metadataPrefix) {
         $finder->setIdentifierTypeExists('urn');
     }
     if (array_key_exists('set', $oaiRequest)) {
         $setarray = explode(':', $oaiRequest['set']);
         if (!isset($setarray[0])) {
             return array();
         }
         if ($setarray[0] == 'doc-type') {
             if (count($setarray) === 2 and !empty($setarray[1])) {
                 $finder->setType($setarray[1]);
             } else {
                 return array();
             }
         } else {
             if ($setarray[0] == 'bibliography') {
                 if (count($setarray) !== 2 or empty($setarray[1])) {
                     return array();
                 }
                 $setValue = $setarray[1];
                 $bibliographyMap = array("true" => 1, "false" => 0);
                 if (false === isset($setValue, $bibliographyMap[$setValue])) {
                     return array();
                 }
                 $finder->setBelongsToBibliography($bibliographyMap[$setValue]);
             } else {
                 if (count($setarray) < 1 or count($setarray) > 2) {
                     $msg = "Invalid SetSpec: Must be in format 'set:subset'.";
                     throw new Oai_Model_Exception($msg);
                 }
                 // Trying to locate collection role and filter documents.
                 $role = Opus_CollectionRole::fetchByOaiName($setarray[0]);
                 if (is_null($role)) {
                     $msg = "Invalid SetSpec: Top level set does not exist.";
                     throw new Oai_Model_Exception($msg);
                 }
                 $finder->setCollectionRoleId($role->getId());
                 // Trying to locate given collection and filter documents.
                 if (count($setarray) == 2) {
                     $subsetName = $setarray[1];
                     $foundSubsets = array_filter($role->getOaiSetNames(), function ($s) use($subsetName) {
                         return $s['oai_subset'] === $subsetName;
                     });
                     if (count($foundSubsets) < 1) {
                         $msg = "Invalid SetSpec: Subset does not exist.";
                         throw new Oai_Model_Exception($msg);
                     }
                     foreach ($foundSubsets as $subset) {
                         if ($subset['oai_subset'] !== $subsetName) {
                             $msg = "Invalid SetSpec: Internal error.";
                             throw new Oai_Model_Exception($msg);
                         }
                         $finder->setCollectionId($subset['id']);
                     }
                 }
             }
         }
     }
     if (array_key_exists('from', $oaiRequest) and !empty($oaiRequest['from'])) {
         $from = DateTime::createFromFormat('Y-m-d', $oaiRequest['from']);
         $finder->setServerDateModifiedAfter($from->format('Y-m-d'));
     }
     if (array_key_exists('until', $oaiRequest)) {
         $until = DateTime::createFromFormat('Y-m-d', $oaiRequest['until']);
         $until->add(new DateInterval('P1D'));
         $finder->setServerDateModifiedBefore($until->format('Y-m-d'));
     }
     return $finder->ids();
 }