Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#6293 consider urnCheckNo setting, fix checkDuplicate in PubIdPlugin #3897

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions classes/plugins/PubIdPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function manage($args, $request) {
$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) {
$issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
$issueDao = DAORegistry::getDAO('IssueDAO'); /** @var IssueDAO $issueDao */
$issues = $issueDao->getPublishedIssues($context->getId());
while ($issue = $issues->next()) {
$issuePubId = $issue->getStoredPubId($this->getPubIdType());
Expand All @@ -46,8 +46,8 @@ function manage($args, $request) {
}
}
}
if ($submissionEnabled || $representationEnabled) {
$publicationDao = DAORegistry::getDAO('PublicationDAO'); /* @var $publicationDao PublicationDAO */
if ($publicationEnabled || $representationEnabled) {
$publicationDao = DAORegistry::getDAO('PublicationDAO'); /** @var PublicationDAO $publicationDao */
$representationDao = Application::getRepresentationDAO();
$submissions = Services::get('submission')->getMany([
'contextId' => $context->getId(),
Expand All @@ -56,7 +56,7 @@ function manage($args, $request) {
]);
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 @@ -102,11 +102,11 @@ function getPubObjectTypes() {
* @copydoc PKPPubIdPlugin::checkDuplicate()
*/
function checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId) {
$issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
$issueDao = DAORegistry::getDAO('IssueDAO'); /** @var IssueDAO $issueDao */
foreach ($this->getPubObjectTypes() as $type) {
if ($type === 'Issue') {
$excludeTypeId = $type === $pubObjectType ? $excludeId : null;
if ($issueDao->pubIdExists($type, $pubId, $excludeTypeId, $contextId)) {
if ($issueDao->pubIdExists($this->getPubIdType(), $pubId, $excludeTypeId, $contextId)) {
return false;
}
}
Expand All @@ -131,7 +131,9 @@ function getPubId($pubObject) {

// Initialize variables for publication objects.
$issue = ($pubObjectType == 'Issue' ? $pubObject : null);
$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);

Expand Down Expand Up @@ -159,7 +161,7 @@ function getPubId($pubObject) {
// Retrieve the issue.
if (!is_a($pubObject, 'Issue')) {
assert(!is_null($submission));
$issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
$issueDao = DAORegistry::getDAO('IssueDAO'); /** @var IssueDAO $issueDao */
$issue = $issueDao->getBySubmissionId($submission->getId(), $contextId);
}
if ($issue && $contextId != $issue->getJournalId()) return null;
Expand Down Expand Up @@ -255,10 +257,10 @@ function getPubId($pubObject) {
* @param $issue Issue
*/
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) return false;
if (!$publicationPubIdEnabled && !$representationPubIdEnabled && !$filePubIdEnabled) return false;

$pubIdType = $this->getPubIdType();
import('lib.pkp.classes.submission.SubmissionFile'); // SUBMISSION_FILE_... constants
Expand All @@ -267,11 +269,11 @@ function clearIssueObjectsPubIds($issue) {
'contextId' => $issue->getJournalId(),
'issueIds' => $issue->getId(),
]);
$publicationDao = DAORegistry::getDAO('PublicationDAO'); /* @var $publicationDao PublicationDAO */
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
$publicationDao = DAORegistry::getDAO('PublicationDAO'); /** @var PublicationDAO $publicationDao */
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /** @var SubmissionFileDAO $submissionFileDao */
foreach ($submissionIds as $submissionId) {
$submission = Services::get('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 ((array) $submission->getData('publications') as $publication) {
$publicationDao->deletePubId($publication->getId(), $pubIdType);
}
Expand Down
2 changes: 2 additions & 0 deletions js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import WorkflowPage from '@/components/Container/WorkflowPageOJS.vue';

// Required by the URN plugin
import FieldText from '@/components/Form/fields/FieldText.vue';
import FieldPubId from '@/components/Form/fields/FieldPubId.vue';

// Expose Vue, the registry and controllers in a global var
window.pkp = Object.assign(PkpLoad, {
Expand All @@ -45,3 +46,4 @@ window.pkp = Object.assign(PkpLoad, {

// Required by the URN plugin
window.pkp.Vue.component('field-text', FieldText);
window.pkp.Vue.component('field-pub-id', FieldPubId);
2 changes: 1 addition & 1 deletion lib/pkp
100 changes: 60 additions & 40 deletions plugins/pubIds/urn/URNPubIdPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @brief URN plugin class
*/


import('classes.plugins.PubIdPlugin');

class URNPubIdPlugin extends PubIdPlugin {
Expand Down Expand Up @@ -220,7 +219,7 @@ function getLinkActions($pubObject) {
function getSuffixPatternsFieldNames() {
return array(
'Issue' => 'urnIssueSuffixPattern',
'Submission' => 'urnPublicationSuffixPattern',
'Publication' => 'urnPublicationSuffixPattern',
'Representation' => 'urnRepresentationSuffixPattern',
);
}
Expand All @@ -247,13 +246,13 @@ function getNotUniqueErrorMsg() {
}

/**
* Add URN to submission, issue or galley properties
* Add URN to publication, issue or galley properties
*
* @param $hookName string <Object>::getProperties::summaryProperties or
* <Object>::getProperties::fullProperties
* @param $args array [
* @option $props array Existing properties
* @option $object Submission|Issue|Galley
* @option $object Publication|Issue|Galley
* @option $args array Request args
* ]
*
Expand All @@ -266,12 +265,12 @@ public function modifyObjectProperties($hookName, $args) {
}

/**
* Add URN submission, issue or galley values
* Add URN publication, issue or galley values
*
* @param $hookName string <Object>::getProperties::values
* @param $args array [
* @option $values array Key/value store of property values
* @option $object Submission|Issue|Galley
* @option $object Publication|Issue|Galley
* @option $props array Requested properties
* @option $args array Request args
* ]
Expand Down Expand Up @@ -362,6 +361,13 @@ public function addPublicationFormFields($hookName, $form) {
$pattern = $this->getSetting($form->submissionContext->getId(), 'urnPublicationSuffixPattern');
}

$appyCheckNumber = $this->getSetting($form->submissionContext->getId(), 'urnCheckNo');

if ($appyCheckNumber) {
// Load the checkNumber.js file that is required for URN fields
$this->addJavaScript(Application::get()->getRequest(), TemplateManager::getManager(Application::get()->getRequest()));
}

// If a pattern exists, use a DOI-like field to generate the URN
if ($pattern) {
$fieldData = [
Expand All @@ -371,8 +377,9 @@ public function addPublicationFormFields($hookName, $form) {
'pattern' => $pattern,
'contextInitials' => $form->submissionContext->getData('acronym', $form->submissionContext->getData('primaryLocale')) ?? '',
'submissionId' => $form->publication->getData('submissionId'),
'assignId' => __('plugins.pubIds.urn.editor.urn.assignUrn'),
'clearId' => __('plugins.pubIds.urn.editor.clearObjectsURN'),
'assignIdLabel' => __('plugins.pubIds.urn.editor.urn.assignUrn'),
'clearIdLabel' => __('plugins.pubIds.urn.editor.clearObjectsURN'),
'applyCheckNumber' => $appyCheckNumber,
];
if ($form->publication->getData('pub-id::publisher-id')) {
$fieldData['publisherId'] = $form->publication->getData('pub-id::publisher-id');
Expand All @@ -393,19 +400,19 @@ public function addPublicationFormFields($hookName, $form) {
} else {
$fieldData['missingPartsLabel'] = __('plugins.pubIds.urn.editor.missingParts');
}
$form->addField(new \PKP\components\forms\FieldPubId('pub-id::other::urn', $fieldData));
$this->import('classes.form.FieldPubIdUrn');
$form->addField(new \Plugins\Generic\URN\FieldPubIdUrn('pub-id::other::urn', $fieldData));

// Otherwise add a field for manual entry that includes a button to generate
// the check number
} else {
// Load the checkNumber.js file that is required for this field
$this->addJavaScript(Application::get()->getRequest(), TemplateManager::getManager(Application::get()->getRequest()));

$this->import('classes.form.FieldUrn');
$form->addField(new \Plugins\Generic\URN\FieldUrn('pub-id::other::urn', [
$this->import('classes.form.FieldTextUrn');
$form->addField(new \Plugins\Generic\URN\FieldTextUrn('pub-id::other::urn', [
'label' => __('plugins.pubIds.urn.displayName'),
'description' => __('plugins.pubIds.urn.editor.urn.description', ['prefix' => $prefix]),
'value' => $form->publication->getData('pub-id::other::urn'),
'urnPrefix' => $prefix,
'applyCheckNumber' => $appyCheckNumber,
]));
}
}
Expand Down Expand Up @@ -480,7 +487,7 @@ public function addPublishFormNotice($hookName, $form) {
}

/**
* Load the FieldUrn Vue.js component into Vue.js
* Load the FieldTextUrn or FieldPubIdUrn Vue.js component into Vue.js
*
* @param string $hookName
* @param array $args
Expand All @@ -493,33 +500,46 @@ public function loadUrnFieldComponent($hookName, $args) {
return;
}

$templateMgr->addJavaScript(
'urn-field-component',
Application::get()->getRequest()->getBaseUrl() . '/' . $this->getPluginPath() . '/js/FieldUrn.js',
[
'contexts' => 'backend',
'priority' => STYLE_SEQUENCE_LAST,
]
);
$context = Application::get()->getRequest()->getContext();
$suffixType = $this->getSetting($context->getId(), 'urnSuffix');
if ($suffixType === 'default' || $suffixType === 'pattern') {
$templateMgr->addJavaScript(
'field-pub-id-urn-component',
Application::get()->getRequest()->getBaseUrl() . '/' . $this->getPluginPath() . '/js/FieldPubIdUrn.js',
[
'contexts' => 'backend',
'priority' => STYLE_SEQUENCE_LAST,
]
);
} else {
$templateMgr->addJavaScript(
'field-text-urn-component',
Application::get()->getRequest()->getBaseUrl() . '/' . $this->getPluginPath() . '/js/FieldTextUrn.js',
[
'contexts' => 'backend',
'priority' => STYLE_SEQUENCE_LAST,
]
);

$templateMgr->addStyleSheet(
'urn-field-component',
'
.pkpFormField--urn__input {
display: inline-block;
}
$templateMgr->addStyleSheet(
'field-text-urn-component',
'
.pkpFormField--urn__input {
display: inline-block;
}

.pkpFormField--urn__button {
margin-left: 0.25rem;
height: 2.5rem; // Match input height
}
',
[
'contexts' => 'backend',
'inline' => true,
'priority' => STYLE_SEQUENCE_LAST,
]
);
.pkpFormField--urn__button {
margin-left: 0.25rem;
height: 2.5rem; // Match input height
}
',
[
'contexts' => 'backend',
'inline' => true,
'priority' => STYLE_SEQUENCE_LAST,
]
);
}
}

//
Expand Down
35 changes: 35 additions & 0 deletions plugins/pubIds/urn/classes/form/FieldPubIdUrn.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* @file plugins/pubIds/urn/classes/form/FieldPubIdUrn.inc.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class FieldPubIdUrn
*
* @brief URN field, that is used for pattern suffixes and that considers check number.
*/

namespace Plugins\Generic\URN;

use PKP\components\forms\FieldPubId;

class FieldPubIdUrn extends FieldPubId
{
/** @copydoc Field::$component */
public $component = 'field-pub-id-urn';

public bool $applyCheckNumber = false;

/**
* @copydoc Field::getConfig()
*/
public function getConfig()
{
$config = parent::getConfig();
$config['applyCheckNumber'] = $this->applyCheckNumber;
return $config;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* @file plugins/pubIds/urn/classes/form/FieldUrn.inc.php
* @file plugins/pubIds/urn/classes/form/FieldTextUrn.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class FieldUrn
* @class FieldTextUrn
* @ingroup classes_controllers_form
*
* @brief A field for entering a URN and then having the check number generated.
Expand All @@ -15,19 +15,22 @@

use PKP\components\forms\FieldText;

class FieldUrn extends FieldText {
class FieldTextUrn extends FieldText {
/** @copydoc Field::$component */
public $component = 'field-urn';
public $component = 'field-text-urn';

/** @var string The urnPrefix from the urn plugin sttings */
public $urnPrefix = '';

public bool $applyCheckNumber = false;

/**
* @copydoc Field::getConfig()
*/
public function getConfig() {
$config = parent::getConfig();
$config['urnPrefix'] = $this->urnPrefix;
$config['applyCheckNumber'] = $this->applyCheckNumber;
$config['addCheckNumberLabel'] = __('plugins.pubIds.urn.editor.addCheckNo');

return $config;
Expand Down
31 changes: 31 additions & 0 deletions plugins/pubIds/urn/js/FieldPubIdUrn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @defgroup plugins_pubIds_urn_js
*/
/**
* @file plugins/pubIds/urn/js/FieldPubIdUrn.js
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief A Vue.js component for URN field, that is used for pattern suffixes and that considers check number.
*/

pkp.Vue.component('field-pub-id-urn', {
name: 'FieldPubIdUrn',
extends: pkp.Vue.component('field-pub-id'),
props: {
applyCheckNumber: {
type: Boolean,
required: true
}
},
methods: {
generateId() {
var id = pkp.Vue.component('field-pub-id').options.methods['generateId'].apply(this);
return this.applyCheckNumber
? id + $.pkp.plugins.generic.urn.getCheckNumber(id, this.prefix)
: id;
}
},
});
Loading