Example #1
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);
 }