コード例 #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;
 }
コード例 #2
0
ファイル: Document.php プロジェクト: alexukua/opus4
 /**
  * Bereitet Formular fuer Anzeige als View vor.
  *
  * Fuegt Unterformular fuer Dateien hinzu. Dateien sind nicht Teil des Metadaten-Formulars, werden aber in der
  * Metadaten-Übersicht mit aufgelistet.
  */
 public function prepareRenderingAsView()
 {
     parent::prepareRenderingAsView();
     if (!is_null($this->document)) {
         if (count($this->document->getFile()) > 0) {
             $subform = new Admin_Form_Document_Files();
             $subform->populateFromModel($this->document);
             $this->addSubForm($subform, 'Files');
         }
     }
 }
コード例 #3
0
ファイル: Container.php プロジェクト: KOBV/opus4-matheon
 /**
  * Returns all associated Opus_File objects that are visible in OAI and accessible by user
  * @return array Accessible Opus_File objects
  *
  * TODO check embargo date
  * TODO merge access checks with code for deliver controller
  */
 public function getAccessibleFiles()
 {
     $realm = Opus_Security_Realm::getInstance();
     // admins sollen immer durchgelassen werden, nutzer nur wenn das doc im publizierten Zustand ist
     if (!$realm->skipSecurityChecks()) {
         // kein administrator
         // PUBLISHED Dokumente sind immer verfügbar (Zugriff auf Modul kann eingeschränkt sein)
         if ($this->_doc->getServerState() !== 'published') {
             // Dokument nicht published
             if (!$realm->checkDocument($this->_docId)) {
                 // Dokument ist nicht verfügbar für aktuellen Nutzer
                 $this->logErrorMessage('document id =' . $this->_docId . ' is not published and access is not allowed for current user');
                 throw new Oai_Model_Exception('access to requested document is forbidden');
             }
         }
         if ($this->_doc->hasEmbargoPassed() === false) {
             if (!$realm->checkDocument($this->_docId)) {
                 // Dokument ist nicht verfügbar für aktuellen Nutzer
                 $this->logErrorMessage('document id =' . $this->_docId . ' is not embargoed and access is not allowed for current user');
                 throw new Oai_Model_Exception('access to requested document files is embargoed');
             }
         }
     }
     $files = array();
     $filesToCheck = $this->_doc->getFile();
     /* @var $file Opus_File */
     foreach ($filesToCheck as $file) {
         $filename = $this->_appConfig->getFilesPath() . $this->_docId . DIRECTORY_SEPARATOR . $file->getPathName();
         if (is_readable($filename)) {
             array_push($files, $file);
         } else {
             $this->logErrorMessage("skip non-readable file {$filename}");
         }
     }
     if (empty($files)) {
         $this->logErrorMessage('document with id ' . $this->_docId . ' does not have any associated files');
         throw new Oai_Model_Exception('requested document does not have any associated readable files');
     }
     $containerFiles = array();
     /* @var $file Opus_File */
     foreach ($files as $file) {
         if ($file->getVisibleInOai() && $realm->checkFile($file->getId())) {
             array_push($containerFiles, $file);
         }
     }
     if (empty($containerFiles)) {
         $this->logErrorMessage('document with id ' . $this->_docId . ' does not have associated files that are accessible');
         throw new Oai_Model_Exception('access denied on all files that are associated to the requested document');
     }
     return $containerFiles;
 }
コード例 #4
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();
 }
コード例 #5
0
ファイル: Document.php プロジェクト: KOBV/opus4-matheon
 /**
  * Render body of notification mail.
  *
  * @param string $baseUrlServer
  * @param string $baseUrlFiles
  * @return string
  */
 public function renderPublishMailBody($baseUrlServer, $baseUrlFiles)
 {
     $baseUrlServer = preg_replace('/[\\/]+$/', '', $baseUrlServer);
     $baseUrlFiles = preg_replace('/[\\/]+$/', '', $baseUrlFiles);
     $loggedUserModel = new Publish_Model_LoggedUser();
     $person = $loggedUserModel->createPerson();
     $submitterString = '';
     if (!is_null($person) and $person->isValid()) {
         $submitterString = trim($person->getFirstName() . " " . $person->getLastName());
     }
     $titleModels = $this->_document->getTitleMain();
     $titleString = '';
     if (count($titleModels) > 0) {
         $titleString = trim($titleModels[0]->getValue());
     }
     $abstractModels = $this->_document->getTitleAbstract();
     $abstractString = '';
     if (count($abstractModels) > 0) {
         $abstractString = trim($abstractModels[0]->getValue());
     }
     $template = new Matheon_Model_Template();
     $template->template = APPLICATION_PATH . '/modules/matheon/models/confirmation-mail.template';
     return $template->render(array('baseUrlServer' => $baseUrlServer, 'baseUrlFiles' => $baseUrlFiles, 'docId' => $this->getId(), 'submitterString' => $submitterString, 'titleString' => $titleString, 'abstractString' => $abstractString, 'files' => $this->_document->getFile()));
 }
コード例 #6
0
 * @copyright   Copyright (c) 2008-2012, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id: find_urns_for_docs_without_visible_files.php 11775 2013-06-25 14:28:41Z tklein $
 */
/**
 * Dieses Script sucht Dokumente ohne sichtbare Dateien, fuer die bereits
 * eine URN vergeben wurde.
 */
$updateRequired = 0;
$docfinder = new Opus_DocumentFinder();
$docfinder->setIdentifierTypeExists('urn');
echo "checking documents...\n";
foreach ($docfinder->ids() as $docId) {
    $doc = new Opus_Document($docId);
    $numVisibleFiles = 0;
    foreach ($doc->getFile() as $file) {
        if ($file->getVisibleInOai() == 1) {
            $numVisibleFiles++;
        }
    }
    if ($numVisibleFiles > 0) {
        continue;
    }
    echo "-- document {$docId} has an URN " . $doc->getIdentifierUrn(0)->getValue() . ", but no visible files\n";
}
if ($updateRequired == 0) {
    echo "all docs were checked -- nothing to do!\n";
} else {
    echo "{$updateRequired} docs need to be updated manually!\n";
}
exit;
コード例 #7
0
 private function _addAccessRights(DOMNode $domNode, Opus_Document $doc)
 {
     $visible = 0;
     $files = $doc->getFile();
     if (count($files) > 0) {
         foreach ($files as $file) {
             if ($file->getField('VisibleInOai')->getValue() && $file->getField('VisibleInFrontdoor')->getValue()) {
                 $visible = 1;
             }
         }
     } else {
         $visible = 1;
     }
     if (!$doc->hasEmbargoPassed()) {
         $visible = 2;
     }
     $fileElement = $domNode->ownerDocument->createElement('Rights');
     switch ($visible) {
         case 0:
             $fileElement->setAttribute('Value', 'info:eu-repo/semantics/closedAccess');
             break;
         case 1:
             $fileElement->setAttribute('Value', 'info:eu-repo/semantics/openAccess');
             break;
         case 2:
             $fileElement->setAttribute('Value', 'info:eu-repo/semantics/embargoedAccess');
             break;
         case 3:
             $fileElement->setAttribute('Value', 'info:eu-repo/semantics/restrictedAccess');
             break;
     }
     $domNode->appendChild($fileElement);
 }
コード例 #8
0
ファイル: FileImport.php プロジェクト: alexukua/opus4
 /**
  * Checks if a file ID is linked to a document.
  * @param int $docId
  * @param int $fileId
  * @return boolean True - if the file is linked to the document
  */
 public function isFileBelongsToDocument($docId, $fileId)
 {
     if (empty($fileId) || !is_numeric($fileId)) {
         return false;
     }
     $doc = new Opus_Document($docId);
     $files = $doc->getFile();
     foreach ($files as $file) {
         if ($file->getId() == $fileId) {
             return true;
         }
     }
     return false;
 }
コード例 #9
0
 /**
  * Regression Test for OPUSVIER-2998 and OPUSVIER-2999
  */
 public function testPublistActionDisplaysUrlencodedFiles()
 {
     Zend_Registry::get('Zend_Config')->merge(new Zend_Config(array('plugins' => array('export' => array('publist' => array('file' => array('allow' => array('mimetype' => array('application/xhtml+xml' => 'HTML')))))))));
     // explicitly re-initialize mime type config to apply changes in Zend_Config
     // This is necessary due to static variable in Export_Model_PublicationList
     // which is not reset between tests.
     $config = Zend_Registry::get('Zend_Config');
     $this->assertTrue(isset($config->plugins->export->publist->file->allow->mimetype), 'Failed setting configuration option');
     $this->assertEquals(array('application/xhtml+xml' => 'HTML'), $config->plugins->export->publist->file->allow->mimetype->toArray(), 'Failed setting configuration option');
     $doc = new Opus_Document(92);
     $file = $doc->getFile(1);
     $this->assertTrue($file instanceof Opus_File, 'Test setup has changed.');
     $this->assertEquals('datei mit unüblichem Namen.xhtml', $file->getPathName(), 'Test setup has changed.');
     $collection = $doc->getCollection(0);
     $this->assertEquals('coll_visible', $collection->getNumber(), 'Test setup has changed');
     $this->assertEquals(1, $collection->getVisible(), 'Test setup has changed');
     $this->dispatch('/export/index/publist/role/publists/number/coll_visible');
     $this->assertResponseCode(200, $this->getResponse()->getBody());
     $response = $this->getResponse();
     $this->assertContains(urlencode('datei mit unüblichem Namen.xhtml'), $response->getBody());
 }
コード例 #10
0
 /**
  * Test verb=GetRecord, prefix=epicur.
  */
 public function testGetRecordEpicurUrlEncoding()
 {
     $expectedFileNames = array("'many'  -  spaces  and  quotes.pdf", 'special-chars-%-"-#-&.pdf');
     $doc = new Opus_Document(147);
     $fileNames = array_map(function ($f) {
         return $f->getPathName();
     }, $doc->getFile());
     sort($fileNames);
     $this->assertEquals(2, count($fileNames), "testdata changed");
     $this->assertEquals($expectedFileNames, $fileNames, "testdata changed");
     $this->dispatch('/oai?verb=GetRecord&metadataPrefix=epicur&identifier=oai::147');
     $this->assertResponseCode(200);
     $response = $this->getResponse();
     $badStrings = array("Exception", "Error", "Stacktrace", "badVerb");
     $this->checkForCustomBadStringsInHtml($response->getBody(), $badStrings);
     $xpath = $this->prepareXpathFromResultString($response->getBody());
     // Regression test for OPUSVIER-2444 - url encoding of transfer files.
     $elements = $xpath->query('//epicur:resource/epicur:identifier[@target="transfer"]/text()');
     $this->assertEquals(2, $elements->length, "Unexpected identifier count");
     $fetchedNames = array();
     foreach ($elements as $element) {
         $fetchedNames[] = preg_replace("/^.*\\/147\\//", "", $element->nodeValue);
     }
     $this->assertContains("special-chars-%25-%22-%23-%26.pdf", $fetchedNames);
     $this->assertContains("%27many%27%20%20-%20%20spaces%20%20and%20%20quotes.pdf", $fetchedNames);
 }
コード例 #11
0
    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);
                    $doc->store();
                }
                _log("Setting ThesisPublisher <{$thesisPublisherId}> on Document <{$docId}>");
            } else {
                $existingThesisPublisherId = $thesisPublisher[0]->getId();
                _log("ThesisPublisher <{$existingThesisPublisherId[1]}> already set for Document <{$docId}>");
            }
コード例 #12
0
 private function extract($startId, $endId)
 {
     $this->forceSyncMode();
     $docIds = $this->getDocumentIds($startId, $endId);
     $extractor = Opus_Search_Service::selectIndexingService('indexBuilder');
     echo date('Y-m-d H:i:s') . " Start indexing of " . count($docIds) . " documents.\n";
     $numOfDocs = 0;
     $runtime = microtime(true);
     // measure time for each document
     foreach ($docIds as $docId) {
         $timeStart = microtime(true);
         $doc = new Opus_Document($docId);
         foreach ($doc->getFile() as $file) {
             try {
                 $extractor->extractDocumentFile($file, $doc);
             } catch (Opus_Search_Exception $e) {
                 echo date('Y-m-d H:i:s') . " ERROR: Failed extracting document {$docId}.\n";
                 echo date('Y-m-d H:i:s') . "        {$e->getMessage()}\n";
             } catch (Opus_Storage_Exception $e) {
                 echo date('Y-m-d H:i:s') . " ERROR: Failed extracting unavailable file on document {$docId}.\n";
                 echo date('Y-m-d H:i:s') . "        {$e->getMessage()}\n";
             }
         }
         $timeDelta = microtime(true) - $timeStart;
         if ($timeDelta > 30) {
             echo date('Y-m-d H:i:s') . " WARNING: Extracting document {$docId} took {$timeDelta} seconds.\n";
         }
         $numOfDocs++;
         if ($numOfDocs % 10 == 0) {
             $this->outputProgress($runtime, $numOfDocs);
         }
     }
     $runtime = microtime(true) - $runtime;
     echo PHP_EOL . date('Y-m-d H:i:s') . ' Finished extracting.' . PHP_EOL;
     // new search API doesn't track number of indexed files, but issues are kept written to log file
     //echo "\n\nErrors appeared in " . $indexer->getErrorFileCount() . " of " . $indexer->getTotalFileCount()
     //    . " files. Details were written to opus-console.log";
     echo PHP_EOL . PHP_EOL . 'Details were written to opus-console.log';
     $this->resetMode();
     return $runtime;
 }
コード例 #13
0
ファイル: DocumentAdapter.php プロジェクト: alexukua/opus4
 public function getFileCount()
 {
     return count($this->document->getFile());
 }
コード例 #14
0
 /**
  * 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');
 }
コード例 #15
0
 public function testGetFieldValues()
 {
     $form = new Admin_Form_Files();
     $document = new Opus_Document(155);
     $files = $document->getFile();
     $values = $form->getFieldValues($document);
     $this->assertEquals(count($files), count($values));
     foreach ($files as $index => $file) {
         $this->assertEquals($file->getId(), $values[$index]->getId(), 'Files are not in expected order.');
     }
 }
コード例 #16
0
ファイル: Files.php プロジェクト: alexukua/opus4
 /**
  * Liefert Opus_File objects for document through getFile function to get proper order of files.
  * @param Opus_Document $document
  * @return array Array of Opus_File objects
  */
 public function getFieldValues($document)
 {
     return $document->getFile();
 }
コード例 #17
0
 public function testDeleteFile()
 {
     $this->model->setImportFolder($this->importFolder);
     $document = $this->createTestDocument();
     $this->documentId = $document->store();
     $filePath1 = $this->importFolder . '/test1.txt';
     file_put_contents($filePath1, 'testfile1');
     $filePath2 = $this->importFolder . '/test2.txt';
     file_put_contents($filePath2, 'testfile2');
     $this->model->addFilesToDocument($this->documentId, array('test1.txt', 'test2.txt'));
     $document = new Opus_Document($this->documentId);
     $files = $document->getFile();
     $this->assertNotNull($files);
     $this->assertEquals(2, count($files));
     $this->assertEquals('test1.txt', $files[0]->getPathName());
     $this->assertEquals('test2.txt', $files[1]->getPathName());
     $this->assertFalse(file_exists($filePath1));
     // deleted after import
     $this->assertFalse(file_exists($filePath2));
     // deleted after import
     // eigentlicher Test
     $this->model->deleteFile($this->documentId, $files[0]->getId());
     $document = new Opus_Document($this->documentId);
     $files = $document->getFile();
     $this->assertNotNull($files);
     $this->assertEquals(1, count($files));
     $this->assertEquals('test2.txt', $files[0]->getPathName());
 }
コード例 #18
0
 * @version     $Id$
 */
/**
 * Removes associated Opus_File objects for all HHAR test documents (id = 1..90)
 * since full text files do not exist in file system
 */
$startId = 1;
$endId = 90;
for ($i = $startId; $i <= $endId; $i++) {
    $d = null;
    try {
        $d = new Opus_Document($i);
    } catch (Opus_Model_NotFoundException $e) {
        // document with id $i does not exist
        continue;
    }
    $files = $d->getFile();
    foreach ($files as $file) {
        try {
            $file->doDelete($file->delete());
        } catch (Exception $e) {
            // ignore exception (is thrown since file does not exist physically)
        }
    }
    $numOfFiles = count($files);
    if ($numOfFiles > 0) {
        echo 'delete ' . $numOfFiles . ' file(s) associated with docId: ' . $d->getId() . "\n";
    }
}
echo "done.\n";
exit;
コード例 #19
0
 /**
  * Regression test for OPUSVIER-1647
  */
 public function testUrlEscapedFileNameDoc147()
 {
     $d = new Opus_Document(147);
     $filePathnames = array();
     foreach ($d->getFile() as $file) {
         $filePathnames[] = $file->getPathName();
     }
     $filenameNormal = 'special-chars-%-"-#-&.pdf';
     $filenameWeird = "'many'  -  spaces  and  quotes.pdf";
     $this->assertContains($filenameNormal, $filePathnames, "testdata changed!");
     $this->assertContains($filenameWeird, $filePathnames, "testdata changed!");
     $this->dispatch('/frontdoor/index/index/docId/147');
     $responseBody = $this->getResponse()->getBody();
     $this->assertRegExp('/<a href="[^"]+\\/\\d+\\/special-chars-%25-%22-%23-%26.pdf">/', $responseBody);
     $this->assertRegExp('/<a href="[^"]+\\/\\d+\\/%27many%27\\+\\+-\\+\\+spaces\\+\\+and\\+\\+quotes.pdf">/', $responseBody);
 }