Ejemplo n.º 1
0
 /**
  * Publishes documents and adds the given Person as referee.
  *
  * @param array $docIds
  * @param mixed $userId
  * @param Opus_Person $person
  *
  * FIXME capture success or failure for display afterwards
  */
 public function clear(array $docIds = null, $userId = null, $person = null)
 {
     $logger = Zend_Registry::get('Zend_Log');
     foreach ($docIds as $docId) {
         $logger->debug('Change state to "published" for document: ' . $docId);
         $document = new Opus_Document($docId);
         $document->setServerState('published');
         $date = new Opus_Date();
         $date->setNow();
         $document->setServerDatePublished($date);
         $document->setPublishedDate($date);
         $guest_role = Opus_UserRole::fetchByName('guest');
         foreach ($document->getFile() as $file) {
             $guest_role->appendAccessFile($file->getId());
         }
         if (isset($person)) {
             $document->addPersonReferee($person);
         }
         $enrichment = $document->addEnrichment();
         $enrichment->setKeyName('review.accepted_by')->setValue($userId);
         // TODO: Put into same transaction...
         $document->store();
         $guest_role->store();
     }
     return;
 }
 public function testClearDocumentWithFile()
 {
     $this->markTestIncomplete('TODO: Re-enable, as soon as OPUSVIER-1220 is fixed.');
     $path = '/tmp/opus4-test/' . uniqid() . "/src";
     mkdir($path, 0777, true);
     $filepath = $path . DIRECTORY_SEPARATOR . "foobar.pdf";
     touch($filepath);
     $document = new Opus_Document($this->documentId);
     $document->addFile()->setTempFile($filepath)->setPathName('foobar.pdf')->setLabel('Volltextdokument (PDF)');
     $document->store();
     $helper = new Review_Model_ClearDocumentsHelper();
     $helper->clear(array($this->documentId), 23, $this->person);
     $document = new Opus_Document($this->documentId);
     $this->assertEquals('published', $document->getServerState());
     $this->assertEquals(1, count($document->getPersonReferee()));
     $enrichments = $document->getEnrichment();
     $this->assertEquals(1, count($enrichments));
     $this->assertEquals(23, $enrichments[0]->getValue());
 }
 * @copyright   Copyright (c) 2008-2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
/**
 * script to create 10000 documents, e.g., for performance testing
 */
for ($i = 1; $i < 10000; $i++) {
    $d = new Opus_Document();
    $d->setServerState('published');
    $d->setType('preprint');
    $d->setLanguage('deu');
    $title = $d->addTitleMain();
    $title->setLanguage('deu');
    $title->setValue('title-' . rand());
    $date = new Opus_Date();
    $date->setNow();
    $date->setYear(1990 + $i % 23);
    $d->setPublishedDate($date);
    $p = new Opus_Person();
    $p->setFirstName("foo-" . $i % 7);
    $p->setLastName("bar-" . $i % 5);
    $p = $d->addPersonAuthor($p);
    $c = new Opus_Collection(15990 + $i % 103);
    $d->addCollection($c);
    $s = $d->addSubject()->setType('ddc');
    $s->setValue($i % 97);
    $docId = $d->store();
    echo "docId: {$docId}\n";
}
exit;
Ejemplo n.º 4
0
 /**
  * Deletes a single file from a document.
  * @param type $docId
  * @param type $fileId
  * @return type
  */
 public function deleteFile($docId, $fileId)
 {
     $doc = new Opus_Document($docId);
     $keepFiles = array();
     $files = $doc->getFile();
     foreach ($files as $index => $file) {
         if ($file->getId() !== $fileId) {
             $keepFiles[] = $file;
         }
     }
     $doc->setFile($keepFiles);
     $doc->store();
 }
Ejemplo n.º 5
0
 public function addDocument($documentId)
 {
     if (is_null($documentId)) {
         throw new Admin_ModelException('missing document id');
     }
     $document = null;
     try {
         $document = new Opus_Document($documentId);
     } catch (Opus_Model_Exception $e) {
         throw new Admin_Model_Exception('invalid document id');
     }
     $document->addCollection($this->_collection);
     $document->store();
 }
Ejemplo n.º 6
0
 public function testGuestAccessToFileRegression3281()
 {
     $this->enableSecurity();
     // test document access as user without access rights
     $doc = $this->createTestDocument();
     $doc->setServerState('published');
     $docId = $doc->store();
     $this->tryAccessForDocument($docId, true);
     $doc = new Opus_Document($docId);
     $doc->setServerState('unpublished');
     $docId = $doc->store();
     $this->tryAccessForDocument($docId, false);
 }
Ejemplo n.º 7
0
 /**
  * Performs state change on document.
  * @param Opus_Document $document
  * @param string $targetState
  *
  * TODO enforcing permissions and throwing exceptions (OPUSVIER-1959)
  */
 public function changeState($document, $targetState)
 {
     switch ($targetState) {
         case 'deleted':
             $document->delete();
             break;
         case 'removed':
             $document->deletePermanent();
             break;
         default:
             $document->setServerState($targetState);
             $document->store();
             break;
     }
 }
 /**
  * Regression test for OPUSVIER-2165
  *
  * if database contains more than one title in the document's language,
  * the first title is used as page title
  */
 public function testFrontdoorTitleRespectsDocumentLanguageMultipleCandidates()
 {
     $d = new Opus_Document(146);
     $lang = $d->getLanguage();
     $d->setLanguage('deu');
     $titles = $d->getTitleMain();
     $d->addTitleMain()->setValue('VBOK')->setLanguage('deu');
     $d->store();
     $this->dispatch('/frontdoor/index/index/docId/146');
     // restore language
     // restore titles
     $d = new Opus_Document(146);
     $d->setLanguage($lang);
     $d->setTitleMain($titles);
     $d->store();
     $this->assertNotContains('<title>OPUS 4 | COLN</title>', $this->getResponse()->getBody());
     $this->assertNotContains('<title>OPUS 4 | VBOK</title>', $this->getResponse()->getBody());
     $this->assertContains('<title>OPUS 4 | KOBV</title>', $this->getResponse()->getBody());
 }
 /**
  * Nach einer Änderung in der Datei soll das ursprüngliche Upload-Datum gesetzt bleiben.
  */
 public function testFileUploadDateAfterModification()
 {
     $this->useGerman();
     $doc = new Opus_Document(305);
     foreach ($doc->getFile() as $file) {
         $file->setComment(rand());
     }
     $docId = $doc->store();
     $this->dispatch('admin/filemanager/index/id/' . $docId);
     $this->assertQueryContentContains('//div', '10.12.2013');
 }
 private function setDocumentType($documenttype)
 {
     $doc = new Opus_Document($this->documentId);
     $doc->setType($documenttype);
     $doc->store();
 }
Ejemplo n.º 11
0
 /**
  * Store current document.
  * 
  * @return integer
  */
 public function store()
 {
     return $this->_document->store();
 }
Ejemplo n.º 12
0
 public function debugAction()
 {
     $this->requirePrivilege('admin');
     $docId = $this->_getParam('docId');
     $document = new Opus_Document($docId);
     $document->setServerState('unpublished');
     $loggedUserModel = new Publish_Model_LoggedUser();
     $loggedUserId = $loggedUserModel->getUserId();
     $document->addEnrichment()->setKeyName('submitter.user_id')->setValue($loggedUserId);
     $document->store();
     $session = new Zend_Session_Namespace('Publish');
     $session->depositConfirmDocumentId = $docId;
 }
 public function testConfirmationDisabled()
 {
     $config = Zend_Registry::get('Zend_Config');
     $config->merge(new Zend_Config(array('confirmation' => array('document' => array('statechange' => array('enabled' => '0'))))));
     $this->dispatch('/admin/workflow/changestate/docId/102/targetState/deleted');
     $this->assertRedirectTo('/admin/document/index/id/102');
     // Änderung wird sofort durchgefuehrt
     $doc = new Opus_Document(102);
     $this->assertEquals('deleted', $doc->getServerState());
     $doc->setServerState('unpublished');
     $doc->store();
 }
Ejemplo n.º 14
0
        echo "sorting documents in series #" . $series->getId() . " numerically\n";
        if (!asort($seriesNumbers, SORT_NUMERIC)) {
            echo "Error while sorting docs -- skip series #" . $series->getId() . "\n";
            break;
        }
    } else {
        echo "sorting documents in series #" . $series->getId() . " lexicographically\n";
        if (!asort($seriesNumbers, SORT_STRING)) {
            echo "Error while sorting docs -- skip series #" . $series->getId() . "\n";
            break;
        }
    }
    $seriesCounter = 0;
    foreach ($seriesNumbers as $docId => $seriesNumber) {
        $doc = new Opus_Document($docId);
        $allSeries = $doc->getSeries();
        $doc->setSeries(array());
        $doc->store();
        foreach ($allSeries as $docSeries) {
            $seriesInstance = $docSeries->getModel();
            if ($seriesInstance->getId() === $series->getId()) {
                echo "reassign doc_sort_order for doc #" . $doc->getId() . " (series number: " . $docSeries->getNumber() . ") -- old / new doc_sort_order: " . $docSeries->getDocSortOrder() . " / " . $seriesCounter . "\n";
                $doc->addSeries($seriesInstance)->setNumber($docSeries->getNumber())->setDocSortOrder($seriesCounter++);
            } else {
                $doc->addSeries($seriesInstance)->setNumber($docSeries->getNumber())->setDocSortOrder($docSeries->getDocSortOrder());
            }
        }
        $doc->store();
    }
}
exit;
Ejemplo n.º 15
0
 /**
  * Loads an old Opus ID
  *
  * @param Opus_Document $object Opus-Document for that the files should be registered
  * @return void
  */
 public function loadSignatureFiles($id)
 {
     $object = new Opus_Document($id);
     $this->_tmpPath = null;
     $opusId = $object->getIdentifierOpus3()->getValue();
     // Search the ID-directory in signaturefiles tree
     $this->searchDir($this->_path, $opusId);
     foreach ($object->getFile() as $file) {
         $sigfiles = $this->getFiles($this->_tmpPath, $file->getPathName());
         if (count($sigfiles) > 0) {
             $key = 0;
             foreach ($sigfiles as $signatureFile) {
                 $registered = false;
                 $signature = implode("", file($signatureFile));
                 // check if this signature has been registered
                 $hashes = $file->getHashValue();
                 foreach ($hashes as $hash) {
                     if (substr($hash->getType(), 0, 4) === 'gpg-') {
                         $key++;
                         if ($signature === $hash->getValue()) {
                             $registered = true;
                         }
                     }
                 }
                 // if not, add the signature
                 if ($registered === false) {
                     $hash = new Opus_HashValues();
                     $hash->setType('gpg-' . $key);
                     $hash->setValue($signature);
                     $file->addHashValue($hash);
                 }
                 unset($signatureFile);
             }
         }
         unset($file);
     }
     // Store signature(s) directly
     $object->store();
 }
Ejemplo n.º 16
0
 /**
  * Im Rahmen der Zuweisung von Dokumenten, die Collections der Collection Role
  * series zugeordnet sind, müssen verschiedene Konflikte behandelt werden.
  *
  * Im Folgenden werden nur Dokumente betrachtet, die mindestens einer Collection
  * der Collection Role series (kurz: series-Collection) zugeordnet sind.
  *
  * Fall 1 (Dokumente ohne IdentifierSerial):
  * Da die Bandnummer einer Schriftenreihe Opus_Series obligatorisch ist, können
  * Dokumente ohne IdentifierSerial nicht migriert werden. Sie verbleiben
  * unangetastet. Die Zuweisung(en) zu series-Collection(s) wird (werden) nicht
  * verändert.
  *
  * Fall 2 (Dokumente mit mehr als einem IdentifierSerial):
  * Da ein Dokument pro Schriftenreihe nur eine Bandnummer besitzen kann, können
  * Dokumente mit mehr als einem Wert für das Feld IdentifierSerial nicht
  * migriert werden. Sie verbleiben unangetastet. Die Zuweisung(en) zu
  * series-Collection(s) wird (werden) nicht verändert.
  *
  * Fall 3 (Dokumente mit einem IdentifierSerial):
  * Da in einer Schriftenreihe nicht zwei Dokumente mit der gleichen Bandnummer
  * existieren können, muss beim Zuweisen von Dokumenten darauf geachtet werden,
  * dass eine Bandnummer nicht mehrfach vergeben wird.
  * Wird versucht ein Dokument zu einer Schriftenreihe mit einer bereits
  * in Benutzung befindlichen Bandnummer zuzuweisen, so wird die Zuweisung
  * nicht durchgeführt. Die Zuweisung des Dokuments zur series-Collection wird
  * in diesem Fall unverändert beibehalten.
  *
  * Im Falle der erfolgreichen Zuweisung des Dokuments zu einer Schriftenreihe
  * wird die Verknüpfung mit der korrespondierenden series-Collection
  * entfernt. Außerdem wird das Feld IdentifierSerial entfernt.
  *
  *
  * @return array an array that contains both the number of conflicts found and
  * the number of documents that were successfully migrated
  */
 private function migrateDocuments()
 {
     $numOfConflicts = 0;
     $numOfDocsMigrated = 0;
     $finder = new Opus_DocumentFinder();
     $finder->setCollectionRoleId($this->seriesRole->getId());
     $serialIdsInUse = array();
     foreach ($finder->ids() as $docId) {
         $doc = new Opus_Document($docId);
         $serialIds = $doc->getIdentifierSerial();
         $numOfSerialIds = count($serialIds);
         if ($numOfSerialIds == 0) {
             $this->logger->warn("doc #{$docId} : does not have a field IdentifierSerial -- leave it untouched");
             $numOfConflicts++;
             continue;
         }
         if ($numOfSerialIds > 1) {
             $this->logger->warn("doc #{$docId} : has {$numOfSerialIds} values for field IdentifierSerial -- leave it untouched");
             $numOfConflicts++;
             continue;
         }
         $serialId = $serialIds[0]->getValue();
         $remainingCollections = array();
         foreach ($doc->getCollection() as $collection) {
             // only consider collection in collection role series
             if ($collection->getRoleId() != $this->seriesRole->getId()) {
                 array_push($remainingCollections, $collection);
             } else {
                 $collectionId = $collection->getId();
                 if (!$collection->isRoot()) {
                     // check for conflict
                     if (array_key_exists($collectionId, $serialIdsInUse) && in_array($serialId, $serialIdsInUse[$collectionId])) {
                         // conflict was found: serialId for series $collectionId already in use
                         $this->logger->warn("doc #{$docId} : could not assign to series #{$collectionId}: value {$serialId} already in use");
                         $this->logger->warn("doc #{$docId} : leave assignment to collection #{$collectionId} untouched");
                         array_push($remainingCollections, $collection);
                         $numOfConflicts++;
                     } else {
                         // no conflict
                         $series = new Opus_Series($collectionId);
                         $doc->addSeries($series)->setNumber($serialId);
                         $doc->setIdentifierSerial(array());
                         // mark usage of serialId for collection $collectionId
                         if (array_key_exists($collectionId, $serialIdsInUse)) {
                             array_push($serialIdsInUse[$collectionId], $serialId);
                         } else {
                             $serialIdsInUse[$collectionId] = array($serialId);
                         }
                         $this->logger->info("doc #{$docId} : assign document to series #{$collectionId} with value {$serialId}");
                         $this->logger->info("doc #{$docId} : removed assignment from collection #{$collectionId}");
                         $this->logger->info("doc #{$docId} : removed field IdentifierSerial with value " . $serialId);
                         $numOfDocsMigrated++;
                     }
                 } else {
                     // series root collection assignment will not be migrated
                     $this->logger->warn("doc #{$docId} : is assigned to root collection #{$collectionId} of collection role series: leave assignment untouched");
                     array_push($remainingCollections, $collection);
                     $numOfConflicts++;
                 }
             }
         }
         $doc->setCollection($remainingCollections);
         $doc->unregisterPlugin('Opus_Document_Plugin_Index');
         $doc->store();
     }
     return array('numOfConflicts' => $numOfConflicts, 'numOfDocsMigrated' => $numOfDocsMigrated);
 }
Ejemplo n.º 17
0
 /**
  * Check if non-admin user has access to unpublished documents.
  * @expectedException Application_Exception
  * @expectedExceptionMessage not allowed
  */
 public function testGetDocumentUnpublished()
 {
     $this->enableSecurity();
     $this->loginUser('security7', 'security7pwd');
     $document = new Opus_Document($this->_documentId);
     $document->setServerState('unpublished');
     $document->store();
     $request = $this->getRequest();
     $request->setParam('docId', $this->_documentId);
     $document = $this->_helper->getDocument($request);
     $this->assertNotNull($document);
     $this->assertEquals($this->_documentId, $document->getId());
 }