From e054636f5a333297194b71a96590534f99361731 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 9 Oct 2024 13:55:22 +0600 Subject: [PATCH 1/5] pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model --- dbscripts/xml/upgrade.xml | 1 + .../Dc11SchemaPublicationFormatAdapter.php | 19 ++++-- plugins/reports/monographReport/Report.php | 46 ++++++++----- tools/cleanReviewerInterests.php | 68 ++++--------------- 4 files changed, 57 insertions(+), 77 deletions(-) diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index 4a655cabf04..35a9adbe13e 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -145,6 +145,7 @@ + diff --git a/plugins/metadata/dc11/filter/Dc11SchemaPublicationFormatAdapter.php b/plugins/metadata/dc11/filter/Dc11SchemaPublicationFormatAdapter.php index b82d270ba79..8969ed858d4 100755 --- a/plugins/metadata/dc11/filter/Dc11SchemaPublicationFormatAdapter.php +++ b/plugins/metadata/dc11/filter/Dc11SchemaPublicationFormatAdapter.php @@ -28,6 +28,7 @@ use APP\publicationFormat\PublicationFormat; use APP\section\Section; use APP\submission\Submission; +use PKP\controlledVocab\ControlledVocab; use PKP\db\DAORegistry; use PKP\facades\Locale; use PKP\i18n\LocaleConversion; @@ -35,8 +36,6 @@ use PKP\metadata\MetadataDescription; use PKP\plugins\Hook; use PKP\plugins\PluginRegistry; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; class Dc11SchemaPublicationFormatAdapter extends MetadataDataObjectAdapter { @@ -99,12 +98,20 @@ public function extractMetadataFromDataObject(&$publicationFormat) } // Subject - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */ - $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */ $supportedLocales = array_keys(Locale::getSupportedFormLocales()); $subjects = array_merge_recursive( - (array) $submissionKeywordDao->getKeywords($publication->getId(), $supportedLocales), - (array) $submissionSubjectDao->getSubjects($publication->getId(), $supportedLocales) + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId(), + $supportedLocales + ), + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId(), + $supportedLocales + ) ); $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects); diff --git a/plugins/reports/monographReport/Report.php b/plugins/reports/monographReport/Report.php index b834821acfe..34e6a713807 100644 --- a/plugins/reports/monographReport/Report.php +++ b/plugins/reports/monographReport/Report.php @@ -32,14 +32,10 @@ use Illuminate\Support\LazyCollection; use IteratorAggregate; use PKP\category\Category; -use PKP\db\DAORegistry; +use PKP\controlledVocab\ControlledVocab; use PKP\facades\Locale; use PKP\security\Role; use PKP\stageAssignment\StageAssignment; -use PKP\submission\SubmissionAgencyDAO; -use PKP\submission\SubmissionDisciplineDAO; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; use PKP\user\User; use PKP\userGroup\UserGroup; use Traversable; @@ -368,9 +364,13 @@ private function getStatus(): string */ private function getKeywords(): string { - /** @var SubmissionKeywordDAO */ - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); - return $this->flattenKeywords($submissionKeywordDao->getKeywords($this->publication->getId())); + return $this->flattenKeywords( + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, + Application::ASSOC_TYPE_PUBLICATION, + $this->publication->getId() + ) + ); } /** @@ -378,9 +378,13 @@ private function getKeywords(): string */ private function getSubjects(): string { - /** @var SubmissionSubjectDAO */ - $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); - return $this->flattenKeywords($submissionSubjectDao->getSubjects($this->publication->getId())); + return $this->flattenKeywords( + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, + Application::ASSOC_TYPE_PUBLICATION, + $this->publication->getId() + ) + ); } /** @@ -388,9 +392,13 @@ private function getSubjects(): string */ private function getDisciplines(): string { - /** @var SubmissionDisciplineDAO */ - $submissionDisciplineDao = DAORegistry::getDAO('SubmissionDisciplineDAO'); - return $this->flattenKeywords($submissionDisciplineDao->getDisciplines($this->publication->getId())); + return $this->flattenKeywords( + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, + Application::ASSOC_TYPE_PUBLICATION, + $this->publication->getId() + ) + ); } /** @@ -398,9 +406,13 @@ private function getDisciplines(): string */ private function getAgencies(): string { - /** @var SubmissionAgencyDAO */ - $submissionAgencyDao = DAORegistry::getDAO('SubmissionAgencyDAO'); - return $this->flattenKeywords($submissionAgencyDao->getAgencies($this->publication->getId())); + return $this->flattenKeywords( + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + Application::ASSOC_TYPE_PUBLICATION, + $this->publication->getId() + ) + ); } /** diff --git a/tools/cleanReviewerInterests.php b/tools/cleanReviewerInterests.php index fbfc7a5c527..ebeb2a2e781 100755 --- a/tools/cleanReviewerInterests.php +++ b/tools/cleanReviewerInterests.php @@ -14,11 +14,11 @@ * @brief CLI tool to remove user interests that are not referenced by any user accounts. */ +use APP\facades\Repo; +use Illuminate\Support\Collection; use PKP\cliTool\CommandLineTool; -use PKP\controlledVocab\ControlledVocabDAO; -use PKP\controlledVocab\ControlledVocabEntryDAO; -use PKP\db\DAORegistry; -use PKP\user\InterestDAO; +use PKP\controlledVocab\ControlledVocabEntry; +use PKP\user\interest\UserInterest; require(dirname(__FILE__) . '/bootstrap.php'); @@ -60,7 +60,7 @@ public function usage() public function execute() { $orphans = $this->_getOrphanVocabInterests(); - if (!count($orphans)) { + if ($orphans->count() === 0) { echo "No user interests to remove.\n"; exit(0); } @@ -68,20 +68,13 @@ public function execute() $command = $this->parameters[0]; switch ($command) { case '--show': - $interests = array_map(function ($entry) { - return $entry->getData(InterestDAO::CONTROLLED_VOCAB_INTEREST); - }, $orphans); + $interests = $orphans->pluck(UserInterest::CONTROLLED_VOCAB_INTEREST)->toArray(); echo "Below are the user interests that are not referenced by any user account.\n"; echo "\t" . join("\n\t", $interests) . "\n"; break; case '--remove': - /** @var ControlledVocabEntryDAO */ - $vocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO'); - foreach ($orphans as $orphanVocab) { - $vocabEntryDao->deleteObject($orphanVocab); - } - echo count($orphans) . " entries deleted\n"; + echo $orphans->toQuery()->delete() . " entries deleted\n"; break; default: @@ -93,50 +86,17 @@ public function execute() /** * Returns user interests that are not referenced - * - * @return array array of ControlledVocabEntry object */ - protected function _getOrphanVocabInterests() + protected function _getOrphanVocabInterests(): Collection { - /** @var InterestDAO */ - $interestDao = DAORegistry::getDAO('InterestDAO'); - /** @var ControlledVocabDAO */ - $vocabDao = DAORegistry::getDAO('ControlledVocabDAO'); - /** @var ControlledVocabEntryDAO */ - $vocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO'); - - $interestVocab = $vocabDao->getBySymbolic(InterestDAO::CONTROLLED_VOCAB_INTEREST); - $vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->getId()); - $vocabEntryList = $vocabEntryIterator->toArray(); - - // list of vocab interests in db - $allInterestVocabIds = array_map( - function ($entry) { - return $entry->getId(); - }, - $vocabEntryList - ); - - // list of vocabs associated to users - $interests = $interestDao->getAllInterests(); - $userInterestVocabIds = array_map( - function ($interest) { - return $interest->getId(); - }, - $interests->toArray() - ); - - // get the difference - $diff = array_diff($allInterestVocabIds, $userInterestVocabIds); - - $orphans = array_filter( - $vocabEntryList, - function ($entry) use ($diff) { - return in_array($entry->getId(), $diff); - } + $controlledVocab = Repo::controlledVocab()->build( + UserInterest::CONTROLLED_VOCAB_INTEREST ); - return $orphans; + return ControlledVocabEntry::query() + ->withControlledVocabId($controlledVocab->id) + ->whereDoesntHave('userInterest') + ->get(); } } From f1410253eaaeafe5c1d9a3620e5214a50230cb0f Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 9 Oct 2024 13:56:35 +0600 Subject: [PATCH 2/5] pkp/pkp-lib#10292 Submodule Update ##touhidurabir/i10292_main## --- lib/pkp | 2 +- plugins/generic/citationStyleLanguage | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pkp b/lib/pkp index e0b14cf1c6f..94148594b3e 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit e0b14cf1c6fc2afc8effbcd52b9b008aa8df0a6e +Subproject commit 94148594b3e7f830780d482eb1f4f39e910118a8 diff --git a/plugins/generic/citationStyleLanguage b/plugins/generic/citationStyleLanguage index c7e90faf16a..97c5752329e 160000 --- a/plugins/generic/citationStyleLanguage +++ b/plugins/generic/citationStyleLanguage @@ -1 +1 @@ -Subproject commit c7e90faf16ac230e1869bcf51c3beb89203113b8 +Subproject commit 97c5752329e4c5b7b01915b66e6e00c234eddab7 From 8ac86900913ce8372f5b632eca58085c59cd10a7 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Fri, 29 Nov 2024 14:04:27 +0600 Subject: [PATCH 3/5] pkp/pkp-lib#10292 Submodule Update ##touhidurabir/i10292_main## --- plugins/reports/reviewReport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/reports/reviewReport b/plugins/reports/reviewReport index 14906b4ced0..0481ed0af93 160000 --- a/plugins/reports/reviewReport +++ b/plugins/reports/reviewReport @@ -1 +1 @@ -Subproject commit 14906b4ced04cbce66d6d8404a56bca9664b8d82 +Subproject commit 0481ed0af93d3cfb38431e4c755572775a397755 From fea9d7f509267f71d7e912e5838515534cd7c214 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Fri, 29 Nov 2024 14:05:07 +0600 Subject: [PATCH 4/5] pkp/pkp-lib#10292 user interest vocab const added --- tools/cleanReviewerInterests.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/cleanReviewerInterests.php b/tools/cleanReviewerInterests.php index ebeb2a2e781..8c923500fb4 100755 --- a/tools/cleanReviewerInterests.php +++ b/tools/cleanReviewerInterests.php @@ -90,7 +90,9 @@ public function execute() protected function _getOrphanVocabInterests(): Collection { $controlledVocab = Repo::controlledVocab()->build( - UserInterest::CONTROLLED_VOCAB_INTEREST + UserInterest::CONTROLLED_VOCAB_INTEREST, + UserInterest::CONTROLLED_VOCAB_INTEREST_ASSOC_TYPE, + UserInterest::CONTROLLED_VOCAB_INTEREST_ASSOC_ID ); return ControlledVocabEntry::query() From 693c49fb5d8323e8ef074995ff0657abea1eff90 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Fri, 20 Dec 2024 19:08:21 +0600 Subject: [PATCH 5/5] pkp/pkp-lib#10292 vocab assoc id nullable and setting anme update form symbolic to name --- dbscripts/xml/upgrade.xml | 2 ++ tools/cleanReviewerInterests.php | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index 35a9adbe13e..71cf2895ce9 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -146,6 +146,8 @@ + + diff --git a/tools/cleanReviewerInterests.php b/tools/cleanReviewerInterests.php index 8c923500fb4..2c44645fbe7 100755 --- a/tools/cleanReviewerInterests.php +++ b/tools/cleanReviewerInterests.php @@ -14,6 +14,7 @@ * @brief CLI tool to remove user interests that are not referenced by any user accounts. */ +use APP\core\Application; use APP\facades\Repo; use Illuminate\Support\Collection; use PKP\cliTool\CommandLineTool; @@ -91,8 +92,8 @@ protected function _getOrphanVocabInterests(): Collection { $controlledVocab = Repo::controlledVocab()->build( UserInterest::CONTROLLED_VOCAB_INTEREST, - UserInterest::CONTROLLED_VOCAB_INTEREST_ASSOC_TYPE, - UserInterest::CONTROLLED_VOCAB_INTEREST_ASSOC_ID + Application::ASSOC_TYPE_SITE, + Application::SITE_CONTEXT_ID, ); return ControlledVocabEntry::query()