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);
 }
Example #2
0
 /**
  * Add URN identifer if no identifier has been added yet.
  *
  * @return void
  */
 protected function _storeIdentifierUrn($identifiers)
 {
     if (!is_array($identifiers)) {
         $identifiers = array($identifiers);
     }
     if ($this->isIdentifierSet($identifiers)) {
         // get constructor values from configuration file
         // if nothing has been configured there, do not build an URN!
         // at least the first two values MUST be set
         $config = Zend_Registry::get('Zend_Config');
         if (isset($config) && is_object($config->urn)) {
             $nid = $config->urn->nid;
             $nss = $config->urn->nss;
             if (!empty($nid) && !empty($nss)) {
                 $urn = new Opus_Identifier_Urn($nid, $nss);
                 $urn_value = $urn->getUrn($this->getId());
                 $urn_model = new Opus_Identifier();
                 $urn_model->setValue($urn_value);
                 $this->setIdentifierUrn($urn_model);
             }
         }
     }
     $options = null;
     if (array_key_exists('options', $this->_externalFields['IdentifierUrn'])) {
         $options = $this->_externalFields['IdentifierUrn']['options'];
     }
     $this->_storeExternal($this->_fields['IdentifierUrn']->getValue(), $options);
 }