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 27, 2023
1 parent 17dc1e0 commit 4600585
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 64 deletions.
26 changes: 16 additions & 10 deletions classes/plugins/PubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public function manage($args, $request)
}

/**
* Handles pubId assignment for any submission, galley, or issue pubIds
* Handles pubId assignment for any publication, galley, or issue pubIds
*/
protected function assignPubIds($request, $context): JSONMessage
{
$suffixFieldName = $this->getSuffixFieldName();
$suffixGenerationStrategy = $this->getSetting($context->getId(), $suffixFieldName);
if ($suffixGenerationStrategy != 'customId') {
$issueEnabled = $this->isObjectTypeEnabled('Issue', $context->getId());
$submissionEnabled = $this->isObjectTypeEnabled('Publication', $context->getId());
$publicationEnabled = $this->isObjectTypeEnabled('Publication', $context->getId());
$representationEnabled = $this->isObjectTypeEnabled('Representation', $context->getId());
if ($issueEnabled) {
$issues = Repo::issue()->getCollector()
Expand All @@ -78,7 +78,7 @@ protected function assignPubIds($request, $context): JSONMessage
}
}
}
if ($submissionEnabled || $representationEnabled) {
if ($publicationEnabled || $representationEnabled) {
$representationDao = Application::getRepresentationDAO();
$submissions = Repo::submission()->getCollector()
->filterByContextIds([$context->getId()])
Expand All @@ -87,7 +87,7 @@ protected function assignPubIds($request, $context): JSONMessage

foreach ($submissions as $submission) {
$publications = $submission->getData('publications');
if ($submissionEnabled) {
if ($publicationEnabled) {
foreach ($publications as $publication) {
$publicationPubId = $publication->getStoredPubId($this->getPubIdType());
if (empty($publicationPubId)) {
Expand Down Expand Up @@ -134,7 +134,7 @@ protected function assignPubIds($request, $context): JSONMessage
public function getPubObjectTypes()
{
$pubObjectTypes = parent::getPubObjectTypes();
$pubObjectTypes['Issue'] = '\Issue'; // FIXME: Add namespacing
$pubObjectTypes['Issue'] = 'APP\issue\Issue';
return $pubObjectTypes;
}

Expand All @@ -156,7 +156,12 @@ public function checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId)
}

/**
* @copydoc PKPPubIdPlugin::getPubId()
* Get the public identifier.
*
* @param object $pubObject
* Publication, Representation, SubmissionFile, Issue
*
* @return string
*/
public function getPubId($pubObject)
{
Expand All @@ -174,7 +179,8 @@ public function getPubId($pubObject)

// Initialize variables for publication objects.
$issue = ($pubObjectType == 'Issue' ? $pubObject : null);
$submission = ($pubObjectType == 'Submission' ? $pubObject : null);
$submission = null;
$publication = ($pubObjectType == 'Publication' ? $pubObject : null);
$representation = ($pubObjectType == 'Representation' ? $pubObject : null);
$submissionFile = ($pubObjectType == 'SubmissionFile' ? $pubObject : null);

Expand Down Expand Up @@ -346,10 +352,10 @@ public static function generateCustomPattern($context, $pubIdSuffix, $pubObject,
*/
public function clearIssueObjectsPubIds($issue)
{
$submissionPubIdEnabled = $this->isObjectTypeEnabled('Publication', $issue->getJournalId());
$publicationPubIdEnabled = $this->isObjectTypeEnabled('Publication', $issue->getJournalId());
$representationPubIdEnabled = $this->isObjectTypeEnabled('Representation', $issue->getJournalId());
$filePubIdEnabled = $this->isObjectTypeEnabled('SubmissionFile', $issue->getJournalId());
if (!$submissionPubIdEnabled && !$representationPubIdEnabled && !$filePubIdEnabled) {
if (!$publicationPubIdEnabled && !$representationPubIdEnabled && !$filePubIdEnabled) {
return false;
}

Expand All @@ -363,7 +369,7 @@ public function clearIssueObjectsPubIds($issue)

foreach ($submissionIds as $submissionId) {
$submission = Repo::submission()->get($submissionId);
if ($submissionPubIdEnabled) { // Does this option have to be enabled here for?
if ($publicationPubIdEnabled) { // Does this option have to be enabled here for?
foreach ($submission->getData('publications') as $publication) {
Repo::publication()->dao->deletePubId($publication->getId(), $pubIdType);
}
Expand Down
62 changes: 8 additions & 54 deletions plugins/pubIds/urn/URNPubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use APP\publication\Publication;
use APP\template\TemplateManager;
use PKP\components\forms\FormComponent;
use PKP\galley\Galley;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\RemoteActionConfirmationModal;
use PKP\plugins\Hook;
Expand All @@ -42,16 +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('Galley::getProperties::summaryProperties', [$this, 'modifyObjectProperties']);
Hook::add('Galley::getProperties::fullProperties', [$this, 'modifyObjectProperties']);
Hook::add('Galley::getProperties::values', [$this, 'modifyObjectPropertyValues']);
Hook::add('Issue::getProperties::summaryProperties', [$this, 'modifyObjectProperties']);
Hook::add('Issue::getProperties::fullProperties', [$this, 'modifyObjectProperties']);
Hook::add('Issue::getProperties::values', [$this, 'modifyObjectPropertyValues']);
Hook::add('Form::config::before', [$this, 'addPublicationFormFields']);
Hook::add('Form::config::before', [$this, 'addPublishFormNotice']);
Hook::add('TemplateManager::display', [$this, 'loadUrnFieldComponent']);
Expand Down Expand Up @@ -253,7 +242,7 @@ public function getSuffixPatternsFieldNames()
{
return [
'Issue' => 'urnIssueSuffixPattern',
'Submission' => 'urnPublicationSuffixPattern',
'Publication' => 'urnPublicationSuffixPattern',
'Representation' => 'urnRepresentationSuffixPattern',
];
}
Expand Down Expand Up @@ -283,50 +272,15 @@ public function getNotUniqueErrorMsg()
}

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

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

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

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

/**
Expand Down

0 comments on commit 4600585

Please sign in to comment.