From 55b885600019dd365bc85156d512b96d17f92f41 Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Mon, 20 Jan 2025 18:40:26 +0100 Subject: [PATCH 1/3] pkp/pkp-lib#10821 Migrate pubid plugin to vue3, Use pkp-button for Apply Number in URN plugin, disable for empty value --- plugins/pubIds/urn/URNPubIdPlugin.php | 19 ++--- plugins/pubIds/urn/js/FieldPubIdUrn.js | 8 +- plugins/pubIds/urn/js/FieldTextUrn.js | 110 ++++++++++++------------- 3 files changed, 68 insertions(+), 69 deletions(-) diff --git a/plugins/pubIds/urn/URNPubIdPlugin.php b/plugins/pubIds/urn/URNPubIdPlugin.php index ea353855528..d5491b17824 100644 --- a/plugins/pubIds/urn/URNPubIdPlugin.php +++ b/plugins/pubIds/urn/URNPubIdPlugin.php @@ -319,10 +319,6 @@ public function addPublicationFormFields(string $hookName, FormComponent $form): $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 = [ @@ -467,12 +463,20 @@ public function loadUrnFieldComponent(string $hookName, array $args): void $templateMgr = $args[0]; $template = $args[1]; - if ($template !== 'workflow/workflow.tpl') { + if ($template !== 'dashboard/editors.tpl') { return; } $context = Application::get()->getRequest()->getContext(); $suffixType = $this->getSetting($context->getId(), 'urnSuffix'); + + $appyCheckNumber = $this->getSetting($context->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 ($suffixType === 'default' || $suffixType === 'pattern') { $templateMgr->addJavaScript( 'field-pub-id-urn-component', @@ -498,11 +502,6 @@ public function loadUrnFieldComponent(string $hookName, array $args): void .pkpFormField--urn__input { display: inline-block; } - - .pkpFormField--urn__button { - margin-left: 0.25rem; - height: 2.5rem; // Match input height - } ', [ 'contexts' => 'backend', diff --git a/plugins/pubIds/urn/js/FieldPubIdUrn.js b/plugins/pubIds/urn/js/FieldPubIdUrn.js index 2bb0a45b38c..f86e5cff517 100644 --- a/plugins/pubIds/urn/js/FieldPubIdUrn.js +++ b/plugins/pubIds/urn/js/FieldPubIdUrn.js @@ -11,9 +11,9 @@ * @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', { +pkp.registry.registerComponent('FieldPubIdUrn', { name: 'FieldPubIdUrn', - extends: pkp.Vue.component('field-pub-id'), + extends: pkp.registry.getComponent('PkpFieldPubId'), props: { applyCheckNumber: { type: Boolean, @@ -22,10 +22,10 @@ pkp.Vue.component('field-pub-id-urn', { }, methods: { generateId() { - var id = pkp.Vue.component('field-pub-id').options.methods['generateId'].apply(this); + var id = pkp.registry.getComponent('PkpFieldPubId').methods['generateId'].apply(this); return this.applyCheckNumber ? id + $.pkp.plugins.generic.urn.getCheckNumber(id, this.prefix) : id; } }, -}); \ No newline at end of file +}) diff --git a/plugins/pubIds/urn/js/FieldTextUrn.js b/plugins/pubIds/urn/js/FieldTextUrn.js index f7625f4cfdb..cfa33ef32f9 100644 --- a/plugins/pubIds/urn/js/FieldTextUrn.js +++ b/plugins/pubIds/urn/js/FieldTextUrn.js @@ -10,76 +10,76 @@ * * @brief A Vue.js component for URN text form field, that is used for custom suffixes, and that considers adding a check number. */ -var template = pkp.Vue.compile('
' + -' ' + -' ' + -'
' + -' ' + -' ' + -' {{ addCheckNumberLabel }}' + -' ' + -' ' + -'
' + -'
' + -' '); -pkp.Vue.component('field-text-urn', { +pkp.registry.registerComponent('FieldTextUrn', { name: 'FieldTextUrn', - extends: pkp.Vue.component('field-text'), + extends: pkp.registry.getComponent('PkpFieldText'), + template: + '
' + + ' ' + + ' ' + + '
' + + ' ' + + ' ' + + ' {{ addCheckNumberLabel }}' + + ' ' + + ' ' + + '
' + + '
', props: { addCheckNumberLabel: { type: String, - required: true + required: true, }, urnPrefix: { type: String, - required: true + required: true, }, applyCheckNumber: { type: Boolean, - required: true - } + required: true, + }, }, methods: { /** * Add a check number to the end of the URN */ addCheckNumber() { - this.currentValue += $.pkp.plugins.generic.urn.getCheckNumber(this.currentValue, this.urnPrefix); - } + this.currentValue += $.pkp.plugins.generic.urn.getCheckNumber( + this.currentValue || '', + this.urnPrefix, + ); + }, }, - render: function(h) { - return template.render.call(this, h); - } -}); \ No newline at end of file +}); From 0de89cb31cbd711110fe063a4ac500a11420e838 Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Wed, 15 Jan 2025 12:25:24 +0100 Subject: [PATCH 2/3] pkp/pkp-lib#9497 fix anyPubIdExists, pubIdExists, checkDuplicate --- classes/monograph/ChapterDAO.php | 2 +- classes/plugins/PubIdPlugin.php | 20 +++++++++---------- classes/press/PressDAO.php | 3 ++- .../PublicationFormatDAO.php | 2 ++ plugins/pubIds/urn/URNPubIdPlugin.php | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/classes/monograph/ChapterDAO.php b/classes/monograph/ChapterDAO.php index 4c03f8eac9d..76f02bf320a 100644 --- a/classes/monograph/ChapterDAO.php +++ b/classes/monograph/ChapterDAO.php @@ -318,7 +318,7 @@ public function pubIdExists(string $pubIdType, string $pubId, int $excludePubObj return DB::table('submission_chapter_settings AS scs') ->join('submission_chapters AS sc', 'scs.chapter_id', '=', 'sc.chapter_id') ->join('publications AS p', 'sc.publication_id', '=', 'p.publication_id') - ->join('submissions AS s', 'p.submission_id', '=', 's.submisison_id') + ->join('submissions AS s', 'p.submission_id', '=', 's.submission_id') ->where('scs.setting_name', '=', "pub-id::{$pubIdType}") ->where('scs.setting_value', '=', $pubId) ->where('sc.chapter_id', '<>', $excludePubObjectId) diff --git a/classes/plugins/PubIdPlugin.php b/classes/plugins/PubIdPlugin.php index f8b5188337e..37826a6ced2 100644 --- a/classes/plugins/PubIdPlugin.php +++ b/classes/plugins/PubIdPlugin.php @@ -221,19 +221,17 @@ public function getDAOs() /** * @copydoc PKPPubIdPlugin::checkDuplicate() */ - public function checkDuplicate($pubId, $pubObjectType, $excludeId, int $contextId) + public function checkDuplicate($pubId, $pubObject, int $contextId) { - /** @var ChapterDAO */ - $chapterDao = DAORegistry::getDAO('ChapterDAO'); - foreach ($this->getPubObjectTypes() as $type => $fqcn) { - if ($type === 'Chapter') { - $excludeTypeId = $type === $pubObjectType ? $excludeId : null; - if ($chapterDao->pubIdExists($this->getPubIdType(), $pubId, $excludeTypeId, $contextId)) { - return false; - } + $allowedPubObjectTypes = $this->getPubObjectTypes(); + if ($pubObject instanceof $allowedPubObjectTypes['Chapter']) { + /** @var ChapterDAO */ + $chapterDao = DAORegistry::getDAO('ChapterDAO'); + if ($chapterDao->pubIdExists($this->getPubIdType(), $pubId, $pubObject->getId(), $contextId)) { + return false; } + return true; } - - return parent::checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId); + return parent::checkDuplicate($pubId, $pubObject, $contextId); } } diff --git a/classes/press/PressDAO.php b/classes/press/PressDAO.php index 86fe5e98757..d90df4c39ff 100644 --- a/classes/press/PressDAO.php +++ b/classes/press/PressDAO.php @@ -1,4 +1,5 @@ Repo::submission()->dao, + Application::ASSOC_TYPE_PUBLICATION => Repo::publication()->dao, Application::ASSOC_TYPE_CHAPTER => DAORegistry::getDAO('ChapterDAO'), Application::ASSOC_TYPE_REPRESENTATION => Application::getRepresentationDAO(), Application::ASSOC_TYPE_SUBMISSION_FILE => Repo::submissionFile()->dao, diff --git a/classes/publicationFormat/PublicationFormatDAO.php b/classes/publicationFormat/PublicationFormatDAO.php index 9a94ce5047c..e3cda37c496 100644 --- a/classes/publicationFormat/PublicationFormatDAO.php +++ b/classes/publicationFormat/PublicationFormatDAO.php @@ -1,4 +1,5 @@ join('publications AS p', 'p.publication_id', '=', 'pf.publication_id') ->join('submissions AS s', 's.submission_id', '=', 'p.submission_id') ->where('pft.setting_name', '=', "pub-id::{$pubIdType}") + ->where('pft.setting_value', '=', $pubId) ->where('pf.publication_format_id', '<>', $excludePubObjectId) ->where('s.context_id', '=', $contextId) ->count() > 0; diff --git a/plugins/pubIds/urn/URNPubIdPlugin.php b/plugins/pubIds/urn/URNPubIdPlugin.php index d5491b17824..cf090929b7c 100644 --- a/plugins/pubIds/urn/URNPubIdPlugin.php +++ b/plugins/pubIds/urn/URNPubIdPlugin.php @@ -286,7 +286,7 @@ public function validatePublicationUrn(string $hookName, array $args): void if (strpos($props['pub-id::other::urn'], $urnPrefix) !== 0) { $urnErrors[] = __('plugins.pubIds.urn.editor.missingPrefix', ['urnPrefix' => $urnPrefix]); } - if (!$this->checkDuplicate($props['pub-id::other::urn'], 'Publication', $submission->getId(), $contextId)) { + if (!$this->checkDuplicate($props['pub-id::other::urn'], $publication, $contextId)) { $urnErrors[] = $this->getNotUniqueErrorMsg(); } if (!empty($urnErrors)) { From f98ab13426aa4ea0894ff77626239dcc914bd6c9 Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Mon, 20 Jan 2025 18:41:08 +0100 Subject: [PATCH 3/3] pkp/pkp-lib#10821 submodule update ##bozana/10821## --- lib/pkp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkp b/lib/pkp index f50463790b3..3fdd61a86aa 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit f50463790b35216af4495257c9d9e06fc3be060d +Subproject commit 3fdd61a86aa5ba6e72aac38304de38dea4c540b5