Exemplo 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;
 }
Exemplo n.º 2
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());
 }
 public function showAction()
 {
     $selectedYear = $this->getRequest()->getParam('selectedYear', null);
     if (is_null($selectedYear) || !in_array($selectedYear, $this->_statisticsModel->getYears())) {
         return $this->_redirectToAndExit('index');
     }
     $this->view->languageSelectorDisabled = true;
     $date = new Opus_Date();
     $date->setYear($selectedYear)->setMonth(12)->setDay(31);
     $this->view->dateThreshold = $this->getHelper('Dates')->getDateString($date);
     $this->view->selectedYear = $selectedYear;
     $this->view->sumDocsUntil = $this->_statisticsModel->getNumDocsUntil($selectedYear);
     $monthStat = $this->_statisticsModel->getMonthStatistics($selectedYear);
     $this->view->totalNumber = array_sum($monthStat);
     $this->view->title = $this->view->translate('Statistic_Controller') . ' ' . $selectedYear;
     $this->view->monthStat = $monthStat;
     $this->view->typeStat = $this->_statisticsModel->getTypeStatistics($selectedYear);
     $this->view->instStat = $this->_statisticsModel->getInstituteStatistics($selectedYear);
     $this->_breadcrumbs->setLabelFor('admin_statistic_show', $selectedYear);
 }
Exemplo n.º 4
0
 protected function invalidateDocumentCacheFor(Opus_Model_AbstractDb $model)
 {
     $documentFinder = new Opus_DocumentFinder();
     $documentFinder->setDependentModel($model);
     $select = $documentFinder->getSelectIds();
     $ids = $documentFinder->Ids();
     $xmlCache = new Opus_Model_Xml_Cache();
     $xmlCache->removeAllEntriesWhereSubSelect($select);
     $date = new Opus_Date();
     $date->setNow();
     Opus_Document::setServerDateModifiedByIds($date, $ids);
 }
Exemplo n.º 5
0
 public function testGetFileObjectForUnpublishedFileForDocumentsAdmin()
 {
     $this->loginUser('security8', 'security8pwd');
     $file = $this->createTestFile('test.pdf');
     $doc = $this->createTestDocument();
     $doc->setServerState('unpublished');
     $doc->addFile($file);
     $date = new Opus_Date();
     $date->setYear('2100')->setMonth('00')->setDay('01');
     $doc->setEmbargoDate($date);
     $docId = $doc->store();
     $model = new Frontdoor_Model_File($docId, "test.pdf");
     $realm = new MockRealm(true, true);
     $opusFile = $model->getFileObject($realm);
     $this->assertEquals("test.pdf", $opusFile->getPathName());
 }
Exemplo n.º 6
0
 /**
  * Dateien dürfen vom Admin heruntergeladen werden, auch wenn das Embargo-Datum nicht vergangen ist.
  * Regressiontest for OPUSVIER-3313.
  */
 public function testAccessForEmbargoedDocumentForAdmin()
 {
     $this->loginUser('admin', 'adminadmin');
     $file = $this->createTestFile('test.pdf');
     $doc = $this->createTestDocument();
     $doc->setServerState('published');
     $doc->addFile($file);
     $date = new Opus_Date();
     $date->setYear('2100')->setMonth('00')->setDay('01');
     $doc->setEmbargoDate($date);
     $docId = $doc->store();
     $model = new Frontdoor_Model_File($docId, "test.pdf");
     $realm = new MockRealm(true, true);
     $file = $model->getFileObject($realm);
     $this->assertEquals('test.pdf', $file->getPathName());
 }
 * @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;
Exemplo n.º 8
0
 /**
  * @expectedException Oai_Model_Exception
  * @expectedExceptionMessage access to requested document files is embargoed
  */
 public function testGetAccessibleFilesForEmbargoedDocument()
 {
     $this->enableSecurity();
     $doc = $this->createTestDocument();
     $doc->setServerState('published');
     // set embargo date to tomorrow
     $date = new Opus_Date();
     $date->setDateTime(new DateTime('tomorrow'));
     $doc->setEmbargoDate($date);
     // add a file visible in OAI
     $file = $this->createTestFile('foo.pdf');
     $file->setVisibleInOai(true);
     $doc->addFile($file);
     $doc->store();
     $this->assertFalse($doc->hasEmbargoPassed());
     // not yet passed
     $container = new Oai_Model_Container($doc->getId());
     $files = $container->getAccessibleFiles();
     $this->assertCount(1, $files);
 }
Exemplo n.º 9
0
 /**
  * Compares EmbargoDate with parameter or system time.
  *
  * @param Opus_Date $now
  * @return bool true - if embargo date has passed; false - if not
  */
 public function hasEmbargoPassed($now = null)
 {
     $embargoDate = $this->getEmbargoDate();
     if (is_null($embargoDate)) {
         return true;
     }
     if (is_null($now)) {
         $now = new Opus_Date();
         $now->setNow();
     }
     // Embargo has passed on the day after the specified date
     $embargoDate->setHour(23);
     $embargoDate->setMinute(59);
     $embargoDate->setSecond(59);
     return $embargoDate < $now;
 }
 /**
  * Tests, that the sortfields in browsing are still working.
  * see Opusvier-3334.
  */
 public function testSortOrderOfDocumentsInBrowsingWithSortfield()
 {
     $olderDoc = $this->createTestDocument();
     $olderDoc->setServerState('published');
     $olderDoc->setLanguage('eng');
     $date = new Opus_Date();
     $date->setNow();
     $date->setDay($date->getDay() - 1);
     $olderDoc->setServerDatePublished($date);
     $olderDoc->setType('article');
     $title = new Opus_Title();
     $title->setValue('zzzOlderDoc');
     // 'zzz' to show the document at the first page
     $title->setLanguage('eng');
     $olderDoc->addTitleMain($title);
     $olderDocId = $olderDoc->store();
     $newerDoc = $this->createTestDocument();
     $newerDoc->setServerState('published');
     $newerDoc->setLanguage('eng');
     $newerDoc->setType('article');
     $title = new Opus_Title();
     $title->setValue('zzzNewerDoc');
     $title->setLanguage('eng');
     $newerDoc->addTitleMain($title);
     $newerDocId = $newerDoc->store();
     $this->dispatch('/solrsearch/index/search/searchtype/simple/query/*%3A*/browsing/true/doctypefq/article/sortfield/title/sortorder/desc');
     $responseBody = $this->getResponse()->getBody();
     preg_match("\$/frontdoor/index/index.*/docId/{$olderDocId}\$", $responseBody, $matches, PREG_OFFSET_CAPTURE);
     $this->assertNotEmpty($matches, "Document {$olderDocId} not found!");
     $olderDocPosition = $matches[0][1];
     preg_match("\$/frontdoor/index/index.*/docId/{$newerDocId}\$", $responseBody, $matches, PREG_OFFSET_CAPTURE);
     $this->assertNotEmpty($matches, "Document {$newerDocId} not found!");
     $newerDocPosition = $matches[0][1];
     $this->assertTrue($newerDocPosition > $olderDocPosition, "Documents are not sorted by sortfield (title).");
 }
Exemplo n.º 11
0
 public function testGetDateStringForInvalidDate()
 {
     $this->useGerman();
     $date = new Opus_Date('2005');
     $this->assertFalse($date->isValid());
     $this->assertEquals(null, $this->__datesHelper->getDateString($date));
 }
 /**
  * Prüft ob das Upload-Datum der Datei bei der Erstellung gesetzt wird.
  */
 public function testFileUploadDate()
 {
     $this->useGerman();
     $file = $this->createTestFile('foo.pdf');
     $file->setVisibleInOai(false);
     $doc = $this->createTestDocument();
     $doc->setServerState('published');
     $doc->addFile($file);
     $docId = $doc->store();
     $dateNow = new Opus_Date();
     $dateNow->setNow();
     $this->dispatch('admin/filemanager/index/id/' . $docId);
     $this->assertQueryContentContains('//label', 'Datum des Hochladens');
     $this->assertQueryContentContains('//div', $dateNow->getDay() . '.' . $dateNow->getMonth() . '.' . $dateNow->getYear());
 }
 *
 * @category    Application
 * @author      Sascha Szott <*****@*****.**>
 * @copyright   Copyright (c) 2008-2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
/**
 * Releases all documents in server state unpublished.
 */
$docFinder = new Opus_DocumentFinder();
$docFinder->setServerState('unpublished');
foreach ($docFinder->ids() as $id) {
    $d = null;
    try {
        $d = new Opus_Document($id);
    } catch (Opus_Model_NotFoundException $e) {
        // document with id $id does not exist
        continue;
    }
    if (!is_null($d)) {
        $date = new Opus_Date();
        $date->setNow();
        $d->setServerState('published');
        $d->setServerDatePublished($date);
        $d->store();
        echo "publishing of document with id {$id} was successful\n";
    }
}
echo "done.\n";
exit;
 /**
  * Test für OPUSVIER-3275.
  */
 public function testEmbargoDateHasNotPassed()
 {
     $this->useEnglish();
     $file = $this->createTestFile('foo.pdf');
     $doc = $this->createTestDocument();
     $doc->setServerState('published');
     $doc->addFile($file);
     $date = new Opus_Date();
     $date->setYear('2100')->setMonth('00')->setDay('01');
     $doc->setEmbargoDate($date);
     $docId = $doc->store();
     $this->dispatch('frontdoor/index/index/docId/' . $docId);
     $this->assertNotQueryContentContains('//*', '/files/' . $docId . '/foo.pdf');
     $this->assertQueryContentContains('//*', 'This document is embargoed until:');
 }
Exemplo n.º 15
0
 /**
  * Copy the uploaded file to it's final destination.
  *
  * Moves or copies uploaded file depending on whether it has been
  * uploaded by PHP process or was privided via filesystem directly.
  *
  * Determine and set file mime type.
  *
  * @see Opus_Model_AbstractDb::_preStore()
  */
 protected function _preStore()
 {
     $result = parent::_preStore();
     if (isset($result)) {
         return $result;
     }
     $target = $this->getPathName();
     $tempFile = $this->getTempFile();
     if (false === empty($tempFile)) {
         $this->getStorage()->createSubdirectory();
         $this->getStorage()->copyExternalFile($tempFile, $target);
         // set file size
         $file_size = $this->getStorage()->getFileSize($target);
         $this->setFileSize($file_size);
         // set mime type
         $mimetype = $this->getStorage()->getFileMimeEncoding($target);
         $this->setMimeType($mimetype);
         // create and append hash values
         $this->_createHashValues();
     }
     // Rename file, if the stored name changed on existing record.  Rename
     // only already stored files.
     // TODO: Move rename logic to _storePathName() method.
     if (false === $this->isNewRecord() && $this->getField('PathName')->isModified()) {
         $storedFileName = $this->_primaryTableRow->path_name;
         if (!empty($storedFileName)) {
             // $oldName = $this->getStorage()->getWorkingDirectory() . $storedFileName;
             $result = $this->getStorage()->renameFile($storedFileName, $target);
         }
     }
     if ($this->isNewRecord()) {
         $dateNow = new Opus_Date();
         $dateNow->setNow();
         $this->setServerDateSubmitted($dateNow);
     }
     return;
 }