-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from OPUS4/4.6.3
OPUSVIER-3894 OPUS 4 Framework 4.6.3 Release
- Loading branch information
Showing
44 changed files
with
5,203 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
START TRANSACTION; | ||
|
||
-- Add two columns to document_identifiers for DOI support | ||
|
||
ALTER TABLE `document_identifiers` | ||
ADD `status` ENUM('registered', 'verified') NULL COMMENT 'DOI registration status', | ||
ADD `registration_ts` TIMESTAMP NULL COMMENT 'timestamp of DOI registration'; | ||
|
||
-- Update database version | ||
|
||
TRUNCATE TABLE `schema_version`; | ||
INSERT INTO `schema_version` (`version`) VALUES (9); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
<?php | ||
/** | ||
* This file is part of OPUS. The software OPUS has been originally developed | ||
* at the University of Stuttgart with funding from the German Research Net, | ||
* the Federal Department of Higher Education and Research and the Ministry | ||
* of Science, Research and the Arts of the State of Baden-Wuerttemberg. | ||
* | ||
* OPUS 4 is a complete rewrite of the original OPUS software and was developed | ||
* by the Stuttgart University Library, the Library Service Center | ||
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg, | ||
* the Saarland University and State Library, the Saxon State Library - | ||
* Dresden State and University Library, the Bielefeld University Library and | ||
* the University Library of Hamburg University of Technology with funding from | ||
* the German Research Foundation and the European Regional Development Fund. | ||
* | ||
* LICENCE | ||
* OPUS is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software | ||
* Foundation; either version 2 of the Licence, or any later version. | ||
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. You should have received a copy of the GNU General Public License | ||
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51 | ||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* @category Framework | ||
* @package Opus_Document_Plugin | ||
* @author Sascha Szott <[email protected]> | ||
* @copyright Copyright (c) 2018, OPUS 4 development team | ||
* @license http://www.gnu.org/licenses/gpl.html General Public License | ||
*/ | ||
|
||
/** | ||
* Plugin for generating identifiers of type DOI. | ||
* | ||
*/ | ||
class Opus_Document_Plugin_IdentifierDoi extends Opus_Model_Plugin_Abstract { | ||
|
||
// was muss hier alles ausgewertet werden: | ||
// automatische Generierung einer DOI für das vorliegende Dokument, wenn | ||
// 1. noch keine DOI vorhanden | ||
// 2. Enrichment opus.doi.autoCreate wurde gesetzt | ||
|
||
// außerdem automatische Registrierung der DOI (Aufruf MDS-Webservice von DataCite) | ||
// wenn DOI vorhanden und die Konfigurationseinstellung doi.registerAtPublish ist auf true/1 gesetzt | ||
|
||
|
||
// laut Spezifikation: jedes OPUS-Dokument kann maximal eine zugeordnete DOI haben | ||
// diese DOI ist entweder lokal oder extern | ||
// im Rahmen der automatischen DOI-Registrierung werden nur lokale DOIs betrachtet | ||
public function postStoreInternal(Opus_Model_AbstractDb $model) { | ||
|
||
$log = Zend_Registry::get('Zend_Log'); | ||
|
||
if (!($model instanceof Opus_Document)) { | ||
$log->err('found unexpected model class ' . get_class($model)); | ||
return; | ||
} | ||
|
||
$serverState = $model->getServerState(); | ||
$log->debug(__CLASS__ . ' postStoreInternal for ' . $model->getDisplayName() . ' and target state ' . $serverState); | ||
|
||
if ($serverState == 'published') { | ||
$this->handlePublishEvent($model, $log); | ||
return; | ||
} | ||
|
||
if ($serverState == 'deleted') { | ||
$this->handleDeleteEvent($model); | ||
return; | ||
} | ||
|
||
$log->err('plugin ' . __CLASS__ . ' is not applicable for documents with server state ' . $serverState); | ||
return; | ||
} | ||
|
||
private function handleDeleteEvent($document) { | ||
// Metadatensatz für DOI auf den Status "inactive" setzen | ||
$doiManager = new Opus_Doi_DoiManager(); | ||
$doiManager->deleteMetadataForDoi($document); | ||
} | ||
|
||
private function handlePublishEvent($document, $log) { | ||
// prüfe zuerst, ob das Dokument das Enrichment opus.doi.autoCreate besitzt | ||
// in diesem Fall wird nun eine DOI gemäß der Konfigurationseinstellungen generiert | ||
$generateDoi = null; | ||
$enrichment = $document->getEnrichment('opus.doi.autoCreate'); | ||
if (!is_null($enrichment)) { | ||
$enrichmentValue = $enrichment->getValue(); | ||
$generateDoi = ($enrichmentValue == 'true'); | ||
$log->debug('found enrichment opus.doi.autoCreate with value ' . $enrichmentValue); | ||
} | ||
|
||
$config = Zend_Registry::get('Zend_Config'); | ||
|
||
if (is_null($generateDoi)) { | ||
// Enrichment opus.doi.autoCreate wurde nicht gefunden - verwende Standardwert für die DOI-Erzeugung aus Konfiguration | ||
$generateDoi = (isset($config->doi->autoCreate) && ($config->doi->autoCreate || $config->doi->autoCreate == '1')); | ||
} | ||
|
||
// prüfe, ob bereits eine DOI mit dem Dokument verknüpft ist | ||
if (!empty($document->getIdentifierDoi())) { | ||
$log->debug('could not assign more than one DOI to document ' . $document->getId()); | ||
} | ||
else { | ||
// $generateDoi kann hier nicht mehr null sein: aktueller Wert entscheidet, ob neue DOI generiert wird | ||
if ($generateDoi) { | ||
try { | ||
$this->addDoi($document, $log); | ||
} | ||
catch (Exception $e) { | ||
$log->err('could not generate local DOI for document ' . $document->getId() . ' - abort DOI registration procedure'); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// prüfe, ob DOI bei DataCite registriert werden soll -> wenn ja, dann Versuch der synchronen Registrierung | ||
$this->registerDoi($document, $log, $config); | ||
} | ||
|
||
/** | ||
* Fügt zum Dokument $model eine DOI hinzu, sofern noch keine existiert und die Konfiguration | ||
* entsprechend gesetzt ist. | ||
* | ||
* @param $model Opus_Document zu dem die DOI hinzugefügt werden soll | ||
*/ | ||
private function addDoi($model, $log) { | ||
|
||
try { | ||
$doiManager = new Opus_Doi_DoiManager(); | ||
$doiValue = $doiManager->generateNewDoi($model); | ||
} | ||
catch (Opus_Doi_DoiException $e) { | ||
$message = 'could not generate DOI value for document ' . $model->getId() . ': ' . $e->getMessage(); | ||
$log->err($message); | ||
throw new Exception($message); | ||
} | ||
|
||
$doi = new Opus_Identifier(); | ||
$doi->setType('doi'); | ||
$doi->setValue($doiValue); | ||
|
||
$identifiers = $model->getIdentifier(); | ||
if (is_null($identifiers)) { | ||
$identifiers = array(); | ||
} | ||
$identifiers[] = $doi; | ||
$model->setIdentifier($identifiers); | ||
|
||
$log->debug('DOI ' . $doiValue . ' was generated for document ' . $model->getId()); | ||
} | ||
|
||
/** | ||
* Registriert die mit dem Dokument verknüpfte DOI bei DataCite unter Verwendung des DoiManagers | ||
* | ||
* @param $model | ||
*/ | ||
private function registerDoi($model, $log, $config) { | ||
|
||
// prüfe ob Konfigurationseinstellung eine Registrierung vorgibt | ||
if (!isset($config->doi->registerAtPublish) || !($config->doi->registerAtPublish || $config->doi->registerAtPublish == '1')) { | ||
$log->debug('registration of DOIs at publish time is disabled in configuration'); | ||
return; | ||
} | ||
|
||
// führe die Registrierung durch | ||
$log->info('start registration of DOI for document ' . $model->getId()); | ||
|
||
try { | ||
$doiManager = new Opus_Doi_DoiManager(); | ||
$registeredDoi = $doiManager->register($model); | ||
if (is_null($registeredDoi)) { | ||
$log->err('could not apply DOI registration on document ' . $model->getId()); | ||
} | ||
} | ||
catch (Opus_Doi_RegistrationException $e) { | ||
$log->err('unexpected error in registration of DOI ' . $e->getDoi() . ' of document ' . $model->getId() . ': ' . $e->getMessage()); | ||
} | ||
catch (Opus_Doi_DoiException $e) { | ||
$log->err('unexpected error in DOI-registration of document ' . $model->getId() . ': ' . $e->getMessage()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,8 @@ | |
* @author Thoralf Klein <[email protected]> | ||
* @copyright Copyright (c) 2009-2010 | ||
* Saechsische Landesbibliothek - Staats- und Universitaetsbibliothek Dresden (SLUB) | ||
* @copyright Copyright (c) 2010-2012, OPUS 4 development team | ||
* @copyright Copyright (c) 2010-2018, OPUS 4 development team | ||
* @license http://www.gnu.org/licenses/gpl.html General Public License | ||
* @version $Id$ | ||
*/ | ||
|
||
/** | ||
|
@@ -41,14 +40,15 @@ | |
* @package Opus_Document_Plugin | ||
* @uses Opus_Model_Plugin_Abstract | ||
*/ | ||
class Opus_Document_Plugin_IdentifierUrn extends Opus_Model_Plugin_Abstract { | ||
class Opus_Document_Plugin_IdentifierUrn extends Opus_Model_Plugin_Abstract | ||
{ | ||
|
||
/** | ||
* 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) { | ||
|
||
public function postStoreInternal(Opus_Model_AbstractDb $model) | ||
{ | ||
if(!($model instanceof Opus_Document)) | ||
return; | ||
|
||
|
@@ -61,18 +61,40 @@ public function postStoreInternal(Opus_Model_AbstractDb $model) { | |
|
||
$log->debug('IdentifierUrn postStoreInternal for ' . $model->getDisplayName()); | ||
|
||
if(!isset($config->urn->autoCreate) or $config->urn->autoCreate != '1') { | ||
// prüfe zuerst, ob das Dokument das Enrichment opus.urn.autoCreate besitzt | ||
// in diesem Fall bestimmt der Wert des Enrichments, ob eine URN beim Publish generiert wird | ||
$generateUrn = null; | ||
$enrichment = $model->getEnrichment('opus.urn.autoCreate'); | ||
if (!is_null($enrichment)) { | ||
$enrichmentValue = $enrichment->getValue(); | ||
$generateUrn = ($enrichmentValue == 'true'); | ||
$log->debug('found enrichment opus.urn.autoCreate with value ' . $enrichmentValue); | ||
} | ||
|
||
if (is_null($generateUrn)) { | ||
// Enrichment opus.urn.autoCreate wurde nicht gefunden - verwende Standardwert für die URN-Erzeugung aus Konfiguration | ||
$generateUrn = (isset($config->urn->autoCreate) && ($config->urn->autoCreate || $config->urn->autoCreate == '1')); | ||
} | ||
|
||
if (!$generateUrn) { | ||
$log->debug('URN auto creation is not configured. skipping...'); | ||
return; | ||
} | ||
|
||
if(!isset($config->urn->nid) || !isset($config->urn->nss)) { | ||
if (!isset($config->urn->nid) || !isset($config->urn->nss)) { | ||
throw new Opus_Document_Exception('URN data is not present in config. Aborting...'); | ||
// FIXME hier sollte keine Exception geworfen werden, weil sonst | ||
// die Ausführung aller nachfolgenden Plugins im Plugin-Array abgebrochen wird | ||
// Plugins werden nämlich in Schleife nacheinander aufgerufen (ohne Exception Handling zwischen | ||
// den einzelnen Aufrufen) | ||
|
||
// FIXME außerdem ist der Exception Type schlecht gewählt, weil es sich in diesem | ||
// Fall ja um einen Konfigurationsfehler handelt und nicht um einen Fehler im Dokument | ||
} | ||
|
||
$log->debug('config.ini is set to support urn auto generation'); | ||
|
||
if($this->urnAlreadyPresent($model)) { | ||
if ($this->urnAlreadyPresent($model)) { | ||
$log->debug('Model ' . $model->getDisplayName() . ' already has a URN. Skipping automatic generation.'); | ||
return; | ||
} | ||
|
@@ -96,6 +118,12 @@ public function postStoreInternal(Opus_Model_AbstractDb $model) { | |
$model->addIdentifierUrn($urn_model); | ||
} | ||
|
||
/** | ||
* Liefert true, wenn das vorliegende Dokument bereits einen Identifier vom Typ URN besitzt; andernfalls false. | ||
* | ||
* @param $document | ||
* @return bool | ||
*/ | ||
public function urnAlreadyPresent($document) { | ||
$identifierUrns = $document->getIdentifierUrn(); | ||
if(count($identifierUrns) > 0) { | ||
|
@@ -112,10 +140,17 @@ public function urnAlreadyPresent($document) { | |
return false; | ||
} | ||
|
||
public function allowUrnOnThisDocument($document) { | ||
/** | ||
* Liefert true, wenn das vorliegende Dokumente mindestens eine Datei mit OAI-Sichtbarkeit besitzt (nur für solche | ||
* Dokumente kann bei der DNB eine URN registriert werden) | ||
* | ||
* @param $document | ||
* @return bool | ||
*/ | ||
public function allowUrnOnThisDocument($document) | ||
{ | ||
$files = array_filter($document->getFile(), | ||
function ($f) { return $f->getVisibleInOai() == 1; }); | ||
return count($files) > 0; | ||
} | ||
} | ||
|
Oops, something went wrong.