Skip to content

Commit

Permalink
pkp/pkp-lib#9497 fix anyPubIdExists, pubIdExists, checkDuplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Jan 20, 2025
1 parent 55b8856 commit 0de89cb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion classes/monograph/ChapterDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions classes/plugins/PubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion classes/press/PressDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/press/PressDAO.php
*
Expand Down Expand Up @@ -106,7 +107,7 @@ public function anyPubIdExists(
$forSameType = false
) {
$pubObjectDaos = [
Application::ASSOC_TYPE_SUBMISSION => 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,
Expand Down
2 changes: 2 additions & 0 deletions classes/publicationFormat/PublicationFormatDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/publicationFormat/PublicationFormatDAO.php
*
Expand Down Expand Up @@ -493,6 +494,7 @@ public function pubIdExists(string $pubIdType, string $pubId, int $excludePubObj
->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;
Expand Down
2 changes: 1 addition & 1 deletion plugins/pubIds/urn/URNPubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 0de89cb

Please sign in to comment.