Skip to content

Commit

Permalink
pkp/pkp-lib#9497 fix checkDuplicate, anyPubIdExists, pubIdExists
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Jan 15, 2025
1 parent 6aa05ec commit fb52fdd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion classes/issue/DAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/issue/DAO.php
*
Expand Down Expand Up @@ -308,7 +309,7 @@ public function pubIdExists(string $pubIdType, string $pubId, int $excludePubObj
return DB::table('issue_settings AS ist')
->join('issues AS i', 'ist.issue_id', '=', 'i.issue_id')
->where('ist.setting_name', '=', "pub-id::{$pubIdType}")
->where('ist.setting_value', '<>', $pubId)
->where('ist.setting_value', '=', $pubId)
->where('i.issue_id', '<>', $excludePubObjectId)
->where('i.journal_id', '=', $contextId)
->count() > 0;
Expand Down
2 changes: 1 addition & 1 deletion classes/journal/JournalDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function anyPubIdExists(
$pubObjectDaos = [
Application::ASSOC_TYPE_ISSUE => Repo::issue()->dao,
Application::ASSOC_TYPE_PUBLICATION => Repo::publication()->dao,
Application::ASSOC_TYPE_GALLEY => Application::getRepresentationDAO(),
Application::ASSOC_TYPE_REPRESENTATION => Application::getRepresentationDAO(),
Application::ASSOC_TYPE_ISSUE_GALLEY => DAORegistry::getDAO('IssueGalleyDAO'),
Application::ASSOC_TYPE_SUBMISSION_FILE => Repo::submissionFile()->dao,
];
Expand Down
16 changes: 7 additions & 9 deletions classes/plugins/PubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,16 @@ public function getPubObjectTypes()
/**
* @copydoc PKPPubIdPlugin::checkDuplicate()
*/
public function checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId)
public function checkDuplicate($pubId, $pubObject, $contextId)
{
foreach ($this->getPubObjectTypes() as $type => $fqcn) {
if ($type === 'Issue') {
$excludeTypeId = $type === $pubObjectType ? $excludeId : null;
if (Repo::issue()->dao->pubIdExists($this->getPubIdType(), $pubId, $excludeTypeId, $contextId)) {
return false;
}
$allowedPubObjectTypes = $this->getPubObjectTypes();
if ($pubObject instanceof $allowedPubObjectTypes['Issue']) {
if (Repo::issue()->dao->pubIdExists($this->getPubIdType(), $pubId, $pubObject->getId(), $contextId)) {
return false;
}
return true;
}

return parent::checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId);
return parent::checkDuplicate($pubId, $pubObject, $contextId);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions plugins/pubIds/urn/URNPubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use APP\plugins\PubIdPlugin;
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\template\TemplateManager;
use PKP\components\forms\FormComponent;
use PKP\components\forms\publication\PKPPublicationIdentifiersForm;
Expand Down Expand Up @@ -157,7 +158,7 @@ public function getPubIdAssignFile()
*/
public function instantiateSettingsForm($contextId)
{
return new classes\form\URNSettingsForm($this, $contextId);
return new URNSettingsForm($this, $contextId);
}

/**
Expand Down Expand Up @@ -312,7 +313,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)) {
Expand Down

0 comments on commit fb52fdd

Please sign in to comment.