/** * 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; }
/** * 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()); }
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); }
* @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;
/** * 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)."); }
/** * 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; }
/** * 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()); }
/** * 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; }