Example #1
0
$thesisPublisherId = @$options['publisherid'] ?: null;
$thesisGrantorId = @$options['grantorid'] ?: null;
$dryrun = isset($options['dryrun']);
try {
    $dnbInstitute = new Opus_DnbInstitute($thesisPublisherId);
} catch (Opus_Model_NotFoundException $omnfe) {
    _log("Opus_DnbInstitute with ID <{$thesisPublisherId}> does not exist.\nExiting...");
    exit;
}
if ($dryrun) {
    _log("TEST RUN: NO DATA WILL BE MODIFIED");
}
$docFinder = new Opus_DocumentFinder();
$docIds = $docFinder->setServerState('published');
if ($documentType != false) {
    $docFinder->setType($documentType);
}
$docIds = $docFinder->ids();
_log(count($docIds) . " documents " . ($documentType != false ? "of type '{$documentType}' " : '') . "found");
foreach ($docIds as $docId) {
    try {
        $doc = new Opus_Document($docId);
        if (count($doc->getFile()) == 0) {
            _log("Document <{$docId}> has no files, skipping..");
            continue;
        }
        if (!is_null($thesisPublisherId)) {
            $thesisPublisher = $doc->getThesisPublisher();
            if (empty($thesisPublisher)) {
                if (!$dryrun) {
                    $doc->setThesisPublisher($dnbInstitute);
 /**
  * Regression test for OPUSVIER-2144
  *
  * IMPORTANT: Unit Test funktioniert nicht mehr, wenn die Zahl der Dokumente 20 übersteigt.
  */
 public function testLastPageUrlEqualsNextPageUrlDocTypeArticle()
 {
     $docFinder = new Opus_DocumentFinder();
     $docFinder->setType('article')->setServerState('published');
     $this->assertEquals(20, $docFinder->count(), "Test data changed!");
     $this->doStandardControllerTest('/solrsearch/index/search/searchtype/simple/query/*%3A*/browsing/true/doctypefq/article', null, null);
     $this->assertTrue(4 == substr_count($this->getResponse()->getBody(), '/solrsearch/index/search/searchtype/simple/query/%2A%3A%2A/browsing/true/doctypefq/article/start/10/rows/10">'));
     $this->assertNotContains('solrsearch/index/search/searchtype/simple/query/%2A%3A%2A/browsing/true/doctypefq/doctoralthesis/start/19/rows/10">', $this->getResponse()->getBody());
     $this->assertEquals(20, $this->getNumOfHits());
 }
Example #3
0
 /**
  * Returns an array of ids for all document of the specified type.
  *
  * @param  string  $typename The name of the document type.
  * @return array Array of document ids.
  *
  * @deprecated
  */
 public static function getIdsForDocType($typename)
 {
     $finder = new Opus_DocumentFinder();
     $finder->setType($typename);
     return $finder->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();
 }
Example #5
0
    echo "script must be executed directy (not via opus-console)\n";
    exit;
}
require_once dirname(__FILE__) . '/../common/bootstrap.php';
$options = getopt('', array('dryrun', 'from:', 'to:'));
$dryrun = isset($options['dryrun']);
if (!isset($options['from']) || empty($options['from']) || !isset($options['to']) || empty($options['to'])) {
    echo "Usage: {$argv[0]} --from <current doc type> --to <target doc type> (--dryrun)\n";
    echo "--from and --to must be provided.\n";
    exit;
}
$from = $options['from'];
$to = $options['to'];
if ($dryrun) {
    _log("TEST RUN: NO DATA WILL BE MODIFIED");
}
$docFinder = new Opus_DocumentFinder();
$docIds = $docFinder->setType($from)->ids();
_log(count($docIds) . " documents found");
foreach ($docIds as $docId) {
    $doc = new Opus_Document($docId);
    $doc->setType($to);
    if (!$dryrun) {
        $doc->store();
    }
    _log("Document #{$docId} changed from '{$from}' to '{$to}'");
}
function _log($message)
{
    echo "{$message}\n";
}