Skip to content

Commit

Permalink
pkp/pkp-lib#8940 do not use submission, use publication instead, clea…
Browse files Browse the repository at this point in the history
…n old code
  • Loading branch information
bozana committed Apr 28, 2023
1 parent 87e5cd6 commit fb031b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 73 deletions.
43 changes: 22 additions & 21 deletions classes/plugins/PubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use PKP\core\DataObject;
use PKP\core\PKPString;
use PKP\db\DAORegistry;

use PKP\plugins\PKPPubIdPlugin;
use PKP\submission\Representation;
use PKP\submissionFile\SubmissionFile;
Expand All @@ -45,7 +44,12 @@ public function getPubObjectTypes()
}

/**
* @copydoc PKPPubIdPlugin::getPubId()
* Get the public identifier.
*
* @param object $pubObject
* Publication, Representation, SubmissionFile, Chapter
*
* @return string
*/
public function getPubId($pubObject)
{
Expand All @@ -62,29 +66,26 @@ public function getPubId($pubObject)
$pubObjectType = $this->getPubObjectType($pubObject);

// Initialize variables for publication objects.
$submission = ($pubObjectType == 'Submission' ? $pubObject : null);
$submission = null;
// Publication is actually handled differently now, but keep it here however for now.
$publication = ($pubObjectType == 'Publication' ? $pubObject : null);
$representation = ($pubObjectType == 'Representation' ? $pubObject : null);
$submissionFile = ($pubObjectType == 'SubmissionFile' ? $pubObject : null);
$chapter = ($pubObjectType == 'Chapter' ? $pubObject : null);

// Get the context id.
if ($pubObjectType == 'Submission') {
$contextId = $pubObject->getContextId();
} else {
// Retrieve the submission.
if (is_a($pubObject, 'Chapter') || is_a($pubObject, 'Representation')) {
$publication = Repo::publication()->get($pubObject->getData('publicationId'));
$submission = Repo::submission()->get($publication->getData('submissionId'));
} else {
assert(is_a($pubObject, 'SubmissionFile'));
$submission = Repo::submission()->get($pubObject->getData('submissionId'));
}
if (!$submission) {
return null;
}
// Now we can identify the context.
$contextId = $submission->getContextId();
// Retrieve the submission.
if (is_a($pubObject, 'Chapter') || is_a($pubObject, 'Representation')) {
$publication = Repo::publication()->get($pubObject->getData('publicationId'));
$submission = Repo::submission()->get($publication->getData('submissionId'));
} else { // Publication or SubmissionFile
$submission = Repo::submission()->get($pubObject->getData('submissionId'));
}
if (!$submission) {
return null;
}
// Now we can identify the context.
$contextId = $submission->getData('contextId');

// Check the context
$context = $this->getContext($contextId);
if (!$context) {
Expand Down Expand Up @@ -214,7 +215,7 @@ public static function generateCustomPattern(
*/
public function getDAOs()
{
return array_merge(parent::getDAOs(), ['Chapter' => DAORegistry::getDAO('ChapterDAO')]);
return array_merge(parent::getDAOs(), [DAORegistry::getDAO('ChapterDAO')]);
}

/**
Expand Down
53 changes: 1 addition & 52 deletions plugins/pubIds/urn/URNPubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use APP\plugins\pubIds\urn\classes\form\FieldPubIdUrn;
use APP\plugins\pubIds\urn\classes\form\FieldTextUrn;
use APP\plugins\pubIds\urn\classes\form\URNSettingsForm;
use APP\publication\Publication;
use APP\template\TemplateManager;
use PKP\components\forms\FormComponent;
use PKP\linkAction\LinkAction;
Expand All @@ -42,9 +41,6 @@ public function register($category, $path, $mainContextId = null)
return $success;
}
if ($success && $this->getEnabled($mainContextId)) {
Hook::add('Publication::getProperties::summaryProperties', [$this, 'modifyObjectProperties']);
Hook::add('Publication::getProperties::fullProperties', [$this, 'modifyObjectProperties']);
Hook::add('Publication::getProperties::values', [$this, 'modifyObjectPropertyValues']);
Hook::add('Publication::validate', [$this, 'validatePublicationUrn']);
Hook::add('Form::config::before', [$this, 'addPublicationFormFields']);
Hook::add('Form::config::before', [$this, 'addPublishFormNotice']);
Expand Down Expand Up @@ -228,7 +224,7 @@ public function getLinkActions($pubObject)
public function getSuffixPatternsFieldNames()
{
return [
'Submission' => 'urnPublicationSuffixPattern',
'Publication' => 'urnPublicationSuffixPattern',
'Representation' => 'urnRepresentationSuffixPattern',
'SubmissionFile' => 'urnSubmissionFileSuffixPattern',
'Chapter' => 'urnChapterSuffixPattern',
Expand Down Expand Up @@ -259,53 +255,6 @@ public function getNotUniqueErrorMsg()
return __('plugins.pubIds.urn.editor.urnSuffixCustomIdentifierNotUnique');
}

/**
* Add URN to submission properties
*
* @param string $hookName <Object>::getProperties::summaryProperties or
* <Object>::getProperties::fullProperties
* @param array $args [
*
* @option $props array Existing properties
* @option $object Publication
* @option $args array Request args
* ]
*/
public function modifyObjectProperties(string $hookName, array $args): void
{
$props = & $args[0];
$props[] = 'pub-id::other::urn';
}

/**
* Add URN submission value
*
* @param string $hookName <Object>::getProperties::values
* @param array $args [
*
* @option $values array Key/value store of property values
* @option $object Publication
* @option $props array Requested properties
* @option $args array Request args
* ]
*/
public function modifyObjectPropertyValues(string $hookName, array $args): void
{
$values = & $args[0];
$object = $args[1];
$props = $args[2];

// URNs are already added to property values for Publications
if ($object instanceof Publication) {
return;
}

if (in_array('pub-id::other::urn', $props)) {
$pubId = $this->getPubId($object);
$values['pub-id::other::urn'] = $pubId ? $pubId : null;
}
}

/**
* Validate a publication's URN against the plugin's settings
*/
Expand Down

0 comments on commit fb031b7

Please sign in to comment.