Esempio n. 1
0
 protected function _preStore()
 {
     $type = $this->getType();
     $value = $this->getValue();
     if (isset($type) and isset($value) and $type === 'urn') {
         $finder = new Opus_DocumentFinder();
         $docIds = $finder->setIdentifierTypeValue('urn', $value)->ids();
         $errorMsg = "urn collision (documents " . implode(",", $docIds) . ")";
         if ($this->isNewRecord() and count($docIds) > 0) {
             throw new Opus_Identifier_UrnAlreadyExistsException($errorMsg);
         }
         if (count($docIds) > 1) {
             throw new Opus_Identifier_UrnAlreadyExistsException($errorMsg);
         }
         if (count($docIds) == 1 and !in_array($this->getParentId(), $docIds)) {
             throw new Opus_Identifier_UrnAlreadyExistsException($errorMsg);
         }
     }
     return parent::_preStore();
 }
Esempio n. 2
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;
 }