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