Example #1
0
 /**
  * Post-store hook will be called right after the document has been stored
  * to the database.
  * 
  * @see {Opus_Model_Plugin_Interface::postStore}
  */
 public function postStore(Opus_Model_AbstractDb $model)
 {
     // only index Opus_File instances
     if (false === $model instanceof Opus_File) {
         $this->getLogger()->err(__METHOD__ . '#1 argument must be instance of Opus_File');
         return;
     }
     // only new Opus_File instances
     if (true !== $model->isNewRecord()) {
         return;
     }
     $config = Zend_Registry::get('Zend_Config');
     if (!is_null($config) && isset($config->securityPolicy->files->defaultAccessRole)) {
         $roleName = $config->securityPolicy->files->defaultAccessRole;
         // Empty name -> don't set any role for access
         if (strlen(trim($roleName)) > 0) {
             $accessRole = Opus_UserRole::fetchByName($roleName);
             if (is_null($accessRole)) {
                 $this->getLogger()->err(__METHOD__ . ": Failed to add role '{$roleName}' to file " . $model->getId() . "; '{$roleName}' role does not exist!");
                 return;
             }
             $accessRole->appendAccessFile($model->getId());
             $accessRole->store();
         }
     }
 }
Example #2
0
 /**
  * Function is only called if document was modified.
  *
  * @see {Opus_Model_Plugin_Interface::postStore}
  */
 public function postStore(Opus_Model_AbstractDb $model)
 {
     $logger = Zend_Registry::get('Zend_Log');
     if (null !== $logger) {
         $logger->debug('Opus_Document_Plugin_XmlCache::postStore() with id ' . $model->getId());
     }
     // TODO can that be eleminated? why is it necessary?
     $model = new Opus_Document($model->getId());
     $cache = new Opus_Model_Xml_Cache();
     $omx = new Opus_Model_Xml();
     // remove document from cache. This can always be done, because postStore is only called if model was modified.
     $cache->removeAllEntriesWhereDocumentId($model->getId());
     // refresh cache (TODO does it make sense?)
     $omx->setStrategy(new Opus_Model_Xml_Version1())->excludeEmptyFields()->setModel($model)->setXmlCache($cache);
     $dom = $omx->getDomDocument();
     // Skip caching of XML-Version2.
     // TODO why?
     $index_version_two = false;
     if ($index_version_two) {
         // xml version 2
         $omx = new Opus_Model_Xml();
         $omx->setStrategy(new Opus_Model_Xml_Version2())->setModel($model)->setXmlCache($cache);
         $dom = $omx->getDomDocument();
     }
 }
Example #3
0
 public function preDelete(Opus_Model_AbstractDb $model)
 {
     if ($model->isNewRecord()) {
         return;
     }
     $this->updateDocuments($model);
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $collections->deleteSubTree($model->getId());
 }
 /**
  * @see {Opus_Model_Plugin_Interface::preDelete}
  * 
  * Run plugin for documents depending on to-be-deleted model.
  * If model is not persistent (i. e. modelId is not set and /or model states to be a new record)
  * preDelete operation is skipped. 
  */
 public function preDelete(Opus_Model_AbstractDb $model)
 {
     $modelId = $model->getId();
     if (!$model->isNewRecord() && !empty($modelId)) {
         $this->invalidateDocumentCacheFor($model);
     }
 }
Example #5
0
 /**
  * Updates documents and deletes collections of CollectionRole.
  * @param Opus_Model_AbstractDb $model
  */
 public function preDelete(Opus_Model_AbstractDb $model)
 {
     if ($model->isNewRecord()) {
         return;
     }
     // Update documents, incl. ServerDateModified
     if ($model instanceof Opus_CollectionRole) {
         $rootCollection = $model->getRootCollection();
         if (!is_null($rootCollection)) {
             $this->updateDocuments($rootCollection);
         }
     }
     // Delete collections belonging to CollectionRole
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $collections->deleteTree($model->getId());
 }
Example #6
0
 /**
  * Generates a new URN for any document that has no URN assigned yet.
  * URN's are generated for Opus_Document instances only.
  */
 public function postStoreInternal(Opus_Model_AbstractDb $model)
 {
     if (!$model instanceof Opus_Document) {
         return;
     }
     if ($model->getServerState() !== 'published') {
         return;
     }
     $config = Zend_Registry::get('Zend_Config');
     $log = Zend_Registry::get('Zend_Log');
     $log->debug('IdentifierUrn postStoreInternal for ' . $model->getDisplayName());
     if (!isset($config->urn->autoCreate) or $config->urn->autoCreate != '1') {
         $log->debug('URN auto creation is not configured. skipping...');
         return;
     }
     if (!isset($config->urn->nid) || !isset($config->urn->nss)) {
         throw new Opus_Document_Exception('URN data is not present in config. Aborting...');
     }
     $log->debug('config.ini is set to support urn auto generation');
     if ($this->urnAlreadyPresent($model)) {
         $log->debug('Model ' . $model->getDisplayName() . ' already has a URN. Skipping automatic generation.');
         return;
     }
     if (!$this->allowUrnOnThisDocument($model)) {
         $log->debug('Model ' . $model->getDisplayName() . ' has no oai-visible files. Skipping automatic URN generation.');
         return;
     }
     $log->debug('Generating URN for document ' . $model->getDisplayName());
     $nid = $config->urn->nid;
     $nss = $config->urn->nss;
     $urn = new Opus_Identifier_Urn($nid, $nss);
     $urn_value = $urn->getUrn($model->getId());
     $urn_model = new Opus_Identifier();
     $urn_model->setValue($urn_value);
     $urn_model->setType('urn');
     $model->addIdentifier($urn_model);
     $model->addIdentifierUrn($urn_model);
 }
Example #7
0
 /**
  * @see {Opus_Model_Plugin_Interface::postStore}
  */
 public function postStoreInternal(Opus_Model_AbstractDb $model)
 {
     $log = Zend_Registry::get('Zend_Log');
     $log->debug('Opus_Document_Plugin_SequenceNumber::postStore() with id ' . $model->getId());
     if (!$model instanceof Opus_Document) {
         $message = 'Model is not an Opus_Document. Aborting...';
         $log->err($message);
         throw new Opus_Document_Exception($message);
     }
     if ($model->getServerState() !== 'published') {
         $message = 'Skip Opus_Documents not in ServerState *published* ...';
         $log->info($message);
         return;
     }
     $config = Zend_Registry::get('Zend_Config');
     if (!isset($config, $config->sequence->identifier_type)) {
         $log->debug('Sequence auto creation is not configured. skipping...');
         return;
     }
     $sequence_type = trim($config->sequence->identifier_type);
     $sequence_ids = array();
     foreach ($model->getIdentifier() as $id) {
         if ($id->getType() === $sequence_type) {
             $sequence_ids[] = trim($id->getValue());
         }
     }
     if (count($sequence_ids) > 0) {
         $message = "Sequence IDs for type '{$sequence_type}' already exists: " . implode(",", $sequence_ids);
         $log->debug($message);
         return;
     }
     // Create and initialize new sequence number...
     $next_sequence_number = $this->_fetchNextSequenceNumber($sequence_type);
     $model->addIdentifier()->setType($sequence_type)->setValue($next_sequence_number);
     return;
 }
Example #8
0
 /**
  * Speichert Datei und verknüpft sie mit dem Dokument.
  *
  * @param Opus_Model_AbstractDb $document
  */
 public function updateModel($document)
 {
     $files = $this->getFileInfo();
     foreach ($files as $file) {
         /* TODO: Uncaught exception 'Zend_File_Transfer_Exception' with message '"fileupload" not found by file transfer adapter
          * if (!$upload->isValid($file)) {
          *    $this->view->message = 'Upload failed: Not a valid file!';
          *    break;
          * }
          */
         $docfile = $document->addFile();
         $docfile->setLabel($this->getElementValue(self::ELEMENT_LABEL));
         $docfile->setComment($this->getElementValue(self::ELEMENT_COMMENT));
         $docfile->setLanguage($this->getElementValue(self::ELEMENT_LANGUAGE));
         $docfile->setSortOrder($this->getElementValue(self::ELEMENT_SORT_ORDER));
         $docfile->setPathName(urldecode($file['name']));
         $docfile->setMimeType($file['type']);
         $docfile->setTempFile($file['tmp_name']);
     }
 }
Example #9
0
 /**
  * Perform actual delete operation if the correct token has been provided.
  *
  * @param string $token Delete token as returned by previous call to delete()
  * @return void
  */
 public function doDelete($token)
 {
     if ($this->_deletionToken === null) {
         throw new Opus_Model_Exception('No deletion token set. Call delete() prior to doDelete().');
     }
     if ($this->_deletionToken !== $token) {
         throw new Opus_Model_Exception('Invalid deletion token passed.');
     }
     parent::delete();
 }
Example #10
0
 /**
  * 
  * Add instance of dependent model as constraint.
  * 
  * @param Opus_Model_AbstractDb $model Instance of dependent model.
  * 
  * @return Opus_DocumentFinder Fluent interface.
  */
 public function setDependentModel($model)
 {
     if (!$model instanceof Opus_Model_AbstractDb) {
         throw new Opus_DocumentFinder_Exception('Expected instance of Opus_Model_AbstractDb.');
     }
     $id = null;
     if ($model instanceof Opus_Model_Dependent_Link_Abstract) {
         $id = $model->getModel()->getId();
     } else {
         $id = $model->getId();
     }
     if (empty($id)) {
         throw new Opus_DocumentFinder_Exception('Id not set for model ' . get_class($model));
     }
     // workaround for Opus_Collection[|Role] which are implemented differently
     if ($model instanceof Opus_Collection) {
         return $this->setCollectionId($id);
     }
     if ($model instanceof Opus_CollectionRole) {
         return $this->setCollectionRoleId($id);
     }
     if (!($model instanceof Opus_Model_Dependent_Abstract || $model instanceof Opus_Model_Dependent_Link_Abstract)) {
         $linkModelClass = $this->_getLinkModelClass($model);
         if (is_null($linkModelClass)) {
             throw new Opus_DocumentFinder_Exception('link model class unknown for model ' . get_class($model));
         }
         $model = new $linkModelClass();
     }
     if (!is_null($id)) {
         $id = $this->db->quote($id);
     }
     $idCol = $model->getParentIdColumn();
     $tableGatewayClass = $model->getTableGatewayClass();
     if (empty($tableGatewayClass)) {
         throw new Opus_DocumentFinder_Exception('No table gateway class provided for ' . get_class($model));
     }
     $table = Opus_Db_TableGateway::getInstance($tableGatewayClass)->info('name');
     if (empty($idCol) || empty($table)) {
         throw new Opus_DocumentFinder_Exception('Cannot create subquery from dependent model ' . get_class($model));
     }
     $idCol = $this->db->quoteIdentifier($idCol);
     $table = $this->db->quoteIdentifier($table);
     if ($model instanceof Opus_Model_Dependent_Link_Abstract) {
         $linkedModelKey = $model->getModelKey();
         if (empty($linkedModelKey)) {
             throw new Opus_DocumentFinder_Exception('Cannot create subquery from dependent model ' . get_class($model));
         }
         $linkedModelKey = $this->db->quoteIdentifier($linkedModelKey);
         $subselect = "SELECT {$idCol}\n                FROM {$table} AS l\n                WHERE l.{$idCol} = d.id\n                AND l.{$linkedModelKey} = {$id}";
     } else {
         if ($model instanceof Opus_Model_Dependent_Abstract) {
             $subselect = "SELECT {$idCol}\n                FROM {$table} AS l\n                WHERE l.{$idCol} = d.id\n                AND l.id = {$id}";
         } else {
             throw new Opus_DocumentFinder_Exception('Cannot create constraint for Model ' . get_class($model));
         }
     }
     $this->select->where("EXISTS ({$subselect})");
     return $this;
 }
Example #11
0
 /**
  * Stores the accounts credentials. Throws exception if something failes
  * during the store operation.
  *
  * @throws Opus_Security_Exception If storing failes.
  * @return void
  */
 public function store()
 {
     // Check for a proper credentials
     if ($this->isValid() === false) {
         throw new Opus_Security_Exception('Credentials are invalid.');
     }
     // Check if there is a account with the same
     // loginname before creating a new record.
     if (is_null($this->getId()) === true) {
         $row = Opus_Account::fetchAccountRowByLogin($this->getLogin());
         if (is_null($row) === false) {
             throw new Opus_Security_Exception('Account with login name ' . $this->getLogin() . ' already exists.');
         }
     }
     // Now really store.
     try {
         return parent::store();
     } catch (Exception $ex) {
         $logger = Zend_Registry::get('Zend_Log');
         if (null !== $logger) {
             $message = "Unknown exception while storing account: ";
             $message .= $ex->getMessage();
             $logger->err(__METHOD__ . ': ' . $message);
         }
         $message = "Caught exception.  Please consult the server logfile.";
         throw new Opus_Security_Exception($message);
     }
 }
Example #12
0
 /**
  * Aktualisiert Instanz von Opus_Licence mit Werte aus Formular.
  * @param Opus_Model_AbstractDb $licence
  */
 public function updateModel($licence)
 {
     $licence->setActive($this->getElementValue(self::ELEMENT_ACTIVE));
     $licence->setCommentInternal($this->getElementValue(self::ELEMENT_COMMENT_INTERNAL));
     $licence->setDescMarkup($this->getElementValue(self::ELEMENT_DESC_MARKUP));
     $licence->setDescText($this->getElementValue(self::ELEMENT_DESC_TEXT));
     $licence->setLanguage($this->getElementValue(self::ELEMENT_LANGUAGE));
     $licence->setLinkLicence($this->getElementValue(self::ELEMENT_LINK_LICENCE));
     $licence->setLinkLogo($this->getElementValue(self::ELEMENT_LINK_LOGO));
     $licence->setMimeType($this->getElementValue(self::ELEMENT_MIME_TYPE));
     $licence->setNameLong($this->getElementValue(self::ELEMENT_NAME_LONG));
     $licence->setSortOrder($this->getElementValue(self::ELEMENT_SORT_ORDER));
     $licence->setPodAllowed($this->getElementValue(self::ELEMENT_POD_ALLOWED));
 }
Example #13
0
 /**
  * Overwrite describe: Do not export external fields to XML.
  *
  * @return array
  */
 public function describe()
 {
     $excludeFields = array('Children', 'Role', 'PendingNodes', 'Parents');
     return array_diff(parent::describe(), $excludeFields);
 }
Example #14
0
 public function getDisplayName()
 {
     return parent::getTitle();
 }
Example #15
0
 /**
  * Set internal fields ServerDatePublished and ServerDateModified.
  *
  * @return mixed Anything else then null will cancel the storage process.
  */
 protected function _preStore()
 {
     $result = parent::_preStore();
     $date = new Opus_Date();
     $date->setNow();
     if (true === $this->isNewRecord()) {
         if (is_null($this->getServerDateCreated())) {
             $this->setServerDateCreated($date);
         }
     }
     $this->setServerDateModified($date);
     if (true === $this->isNewRecord() || true === $this->isModified()) {
         // Initially set ServerDatePublished if ServerState == 'published'
         if ($this->getServerState() === 'published') {
             if (is_null($this->getServerDatePublished())) {
                 $this->setServerDatePublished($date);
             }
         }
     }
     return $result;
 }
Example #16
0
 /**
  * Set SHA1 hash column value to table row.
  *
  * @return mixed Database id.
  */
 protected function _preStore()
 {
     $this->_primaryTableRow->sha1_id = $this->getSha1Id();
     return parent::_preStore();
 }
Example #17
0
 /**
  * Overriding isModified() method.  Returning TRUE if the pending queues
  * have been changed, otherwise call parent::isModified().
  *
  * @return boolean
  */
 public function isModified()
 {
     if (count($this->_pendingAccessResources) > 0) {
         return true;
     }
     return parent::isModified();
 }
Example #18
0
 /**
  * Field to be removed.  See ticket OPUSVIER-2155.
  * TODO: Hack to remove field DisplayOai from admin forms.
  */
 public function describe()
 {
     $fields = parent::describe();
     return array_diff($fields, array('DisplayOai'));
 }