コード例 #1
0
ファイル: FileImport.php プロジェクト: alexukua/opus4
 /**
  *
  * @param string $docId
  * @param array $files
  * @throws Application_Exception in case database contains no document with id $docID
  */
 public function addFilesToDocument($docId, $files)
 {
     if (empty($files)) {
         throw new Application_Exception('no files for import');
     }
     $document = null;
     try {
         $document = new Opus_Document($docId);
     } catch (Opus_Model_NotFoundException $e) {
         throw new Application_Exception('no document found for id ' . $docId, null, $e);
     }
     $log = $this->getLogger();
     $validFilenames = $this->getNamesOfIncomingFiles();
     foreach ($files as $file) {
         $log->debug('check filename ' . $file);
         if (in_array($file, $validFilenames)) {
             $pathname = $this->__importFolder . DIRECTORY_SEPARATOR . $file;
             $log->info('import file ' . $pathname);
             $docfile = $document->addFile();
             $docfile->setTempFile($pathname);
             $docfile->setPathName($file);
             $docfile->setLabel($file);
             try {
                 $document->store();
                 $log->info('import of file ' . $pathname . ' successful');
             } catch (Exception $e) {
                 $log->err('import of file ' . $pathname . ' failed: ' . $e->getMessage());
             }
             $log->info('try to delete file ' . $pathname);
             if (!unlink($pathname)) {
                 $log->err('could not delete file ' . $pathname);
             }
         }
     }
 }
コード例 #2
0
 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());
 }