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