diff --git a/classes/migration/upgrade/v3_5_0/I10292_AddPrimaryKeyToUserInterestsTable.php b/classes/migration/upgrade/v3_5_0/I10292_AddPrimaryKeyToUserInterestsTable.php new file mode 100644 index 00000000000..3d140eb2f4d --- /dev/null +++ b/classes/migration/upgrade/v3_5_0/I10292_AddPrimaryKeyToUserInterestsTable.php @@ -0,0 +1,43 @@ +bigIncrements('user_interest_id')->first(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_interests', function (Blueprint $table) { + $table->dropColumn('user_interest_id'); + }); + } +} diff --git a/classes/search/ArticleSearch.php b/classes/search/ArticleSearch.php index 7d25044fd42..ee3ee86dfd7 100644 --- a/classes/search/ArticleSearch.php +++ b/classes/search/ArticleSearch.php @@ -28,6 +28,7 @@ use PKP\plugins\Hook; use PKP\search\SubmissionSearch; use PKP\submission\PKPSubmission; +use PKP\submission\SubmissionKeywordVocab; class ArticleSearch extends SubmissionSearch { @@ -199,7 +200,7 @@ public function getSearchFilters($request) $context = $contextDao->getById($searchFilters['searchJournal']); } elseif (array_key_exists('journalTitle', $request->getUserVars())) { $contexts = $contextDao->getAll(true); - while ($context = $contexts->next()) { + while ($context = $contexts->next()) { /** @var \PKP\context\Context $context */ if (in_array( $request->getUserVar('journalTitle'), (array) $context->getName(null) @@ -333,8 +334,7 @@ public function getSimilarityTerms($submissionId) $article = Repo::submission()->get($submissionId); if ($article->getData('status') === PKPSubmission::STATUS_PUBLISHED) { // Retrieve keywords (if any). - $submissionSubjectDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var \PKP\submission\SubmissionKeywordDAO $submissionSubjectDao */ - $allSearchTerms = array_filter($submissionSubjectDao->getKeywords($article->getCurrentPublication()->getId(), [Locale::getLocale(), $article->getData('locale'), Locale::getPrimaryLocale()])); + $allSearchTerms = array_filter(SubmissionKeywordVocab::getKeywords($article->getCurrentPublication()->getId(), [Locale::getLocale(), $article->getData('locale'), Locale::getPrimaryLocale()])); foreach ($allSearchTerms as $locale => $localeSearchTerms) { $searchTerms += $localeSearchTerms; } diff --git a/plugins/importexport/doaj/filter/DOAJJsonFilter.php b/plugins/importexport/doaj/filter/DOAJJsonFilter.php index e78518132af..c4fa514d6af 100644 --- a/plugins/importexport/doaj/filter/DOAJJsonFilter.php +++ b/plugins/importexport/doaj/filter/DOAJJsonFilter.php @@ -21,9 +21,8 @@ use APP\plugins\importexport\doaj\DOAJExportDeployment; use APP\plugins\importexport\doaj\DOAJExportPlugin; use PKP\core\PKPString; -use PKP\db\DAORegistry; use PKP\plugins\importexport\PKPImportExportFilter; -use PKP\submission\SubmissionKeywordDAO; +use PKP\submission\SubmissionKeywordVocab; class DOAJJsonFilter extends PKPImportExportFilter { @@ -176,9 +175,7 @@ public function &process(&$pubObject) $article['bibjson']['abstract'] = PKPString::html2text($abstract); } // Keywords - /** @var SubmissionKeywordDAO */ - $dao = DAORegistry::getDAO('SubmissionKeywordDAO'); - $keywords = $dao->getKeywords($publication->getId(), [$publicationLocale]); + $keywords = SubmissionKeywordVocab::getKeywords($publication->getId(), [$publicationLocale]); $allowedNoOfKeywords = array_slice($keywords[$publicationLocale] ?? [], 0, 6); if (!empty($keywords[$publicationLocale])) { $article['bibjson']['keywords'] = $allowedNoOfKeywords; diff --git a/plugins/importexport/doaj/filter/DOAJXmlFilter.php b/plugins/importexport/doaj/filter/DOAJXmlFilter.php index d5817b9f28f..522ad0c7ea7 100644 --- a/plugins/importexport/doaj/filter/DOAJXmlFilter.php +++ b/plugins/importexport/doaj/filter/DOAJXmlFilter.php @@ -21,9 +21,8 @@ use APP\publication\Publication; use APP\submission\Submission; use PKP\core\PKPString; -use PKP\db\DAORegistry; use PKP\i18n\LocaleConversion; -use PKP\submission\SubmissionKeywordDAO; +use PKP\submission\SubmissionKeywordVocab; class DOAJXmlFilter extends \PKP\plugins\importexport\native\filter\NativeExportFilter { @@ -189,16 +188,17 @@ public function &process(&$pubObjects) $request = Application::get()->getRequest(); $recordNode->appendChild($node = $doc->createElement('fullTextUrl', htmlspecialchars($request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'article', 'view', [$pubObject->getId()], urlLocaleForPage: ''), ENT_COMPAT, 'UTF-8'))); $node->setAttribute('format', 'html'); + // Keywords $supportedLocales = $context->getSupportedFormLocales(); - /** @var SubmissionKeywordDAO */ - $dao = DAORegistry::getDAO('SubmissionKeywordDAO'); - $articleKeywords = $dao->getKeywords($publication->getId(), $supportedLocales); + $articleKeywords = SubmissionKeywordVocab::getKeywords($publication->getId(), $supportedLocales); + if (array_key_exists($publication->getData('locale'), $articleKeywords)) { $keywordsInArticleLocale = $articleKeywords[$publication->getData('locale')]; unset($articleKeywords[$publication->getData('locale')]); $articleKeywords = array_merge([$publication->getData('locale') => $keywordsInArticleLocale], $articleKeywords); } + foreach ($articleKeywords as $locale => $keywords) { $keywordsNode = $doc->createElement('keywords'); $keywordsNode->setAttribute('language', LocaleConversion::get3LetterIsoFromLocale($locale)); diff --git a/plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php b/plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php index c084c17eb2c..ae50c911fcc 100644 --- a/plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php +++ b/plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php @@ -35,8 +35,8 @@ use PKP\metadata\MetadataDescription; use PKP\plugins\Hook; use PKP\plugins\PluginRegistry; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; +use PKP\submission\SubmissionKeywordVocab; +use PKP\submission\SubmissionSubjectVocab; class Dc11SchemaArticleAdapter extends MetadataDataObjectAdapter { @@ -90,12 +90,10 @@ public function &extractMetadataFromDataObject(&$article) } // Subject - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */ - $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */ $supportedLocales = $journal->getSupportedFormLocales(); $subjects = array_merge_recursive( - (array) $submissionKeywordDao->getKeywords($publication->getId(), $supportedLocales), - (array) $submissionSubjectDao->getSubjects($publication->getId(), $supportedLocales) + SubmissionKeywordVocab::getKeywords($publication->getId(), $supportedLocales), + SubmissionSubjectVocab::getSubjects($publication->getId(), $supportedLocales) ); $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects); diff --git a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php index 71449fcd7cf..9c15bbf0709 100755 --- a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php +++ b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php @@ -45,8 +45,6 @@ use PKP\galley\Collector as GalleyCollector; use PKP\galley\Galley; use PKP\oai\OAIRecord; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; use PKP\tests\PKPTestCase; #[CoversClass(OAIMetadataFormat_DC::class)] @@ -58,7 +56,7 @@ class OAIMetadataFormat_DCTest extends PKPTestCase */ protected function getMockedDAOs(): array { - return [...parent::getMockedDAOs(), 'OAIDAO', 'SubmissionSubjectDAO', 'SubmissionKeywordDAO']; + return [...parent::getMockedDAOs(), 'OAIDAO']; } /** @@ -263,25 +261,6 @@ public function testToXml() ->willReturn(LazyCollection::wrap($galleys)); app()->instance(GalleyCollector::class, $mockGalleyCollector); - // Mocked DAO to return the subjects - $submissionSubjectDao = $this->getMockBuilder(SubmissionSubjectDAO::class) - ->onlyMethods(['getSubjects']) - ->getMock(); - $submissionSubjectDao->expects($this->any()) - ->method('getSubjects') - ->willReturn(['en' => ['article-subject', 'article-subject-class']]); - DAORegistry::registerDAO('SubmissionSubjectDAO', $submissionSubjectDao); - - // Mocked DAO to return the keywords - $submissionKeywordDao = $this->getMockBuilder(SubmissionKeywordDAO::class) - ->onlyMethods(['getKeywords']) - ->getMock(); - $submissionKeywordDao->expects($this->any()) - ->method('getKeywords') - ->willReturn(['en' => ['article-keyword']]); - DAORegistry::registerDAO('SubmissionKeywordDAO', $submissionKeywordDao); - - // // Test // diff --git a/plugins/oaiMetadataFormats/rfc1807/OAIMetadataFormat_RFC1807.php b/plugins/oaiMetadataFormats/rfc1807/OAIMetadataFormat_RFC1807.php index e474187493b..b1b73b50de2 100644 --- a/plugins/oaiMetadataFormats/rfc1807/OAIMetadataFormat_RFC1807.php +++ b/plugins/oaiMetadataFormats/rfc1807/OAIMetadataFormat_RFC1807.php @@ -18,11 +18,10 @@ use APP\core\Application; use APP\issue\IssueAction; -use PKP\db\DAORegistry; use PKP\oai\OAIMetadataFormat; use PKP\oai\OAIUtils; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; +use PKP\submission\SubmissionKeywordVocab; +use PKP\submission\SubmissionSubjectVocab; class OAIMetadataFormat_RFC1807 extends OAIMetadataFormat { @@ -68,11 +67,9 @@ public function toXml($record, $format = null) // Subject $supportedLocales = $journal->getSupportedFormLocales(); - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */ - $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */ $subjects = array_merge_recursive( - (array) $submissionKeywordDao->getKeywords($publication->getId(), $supportedLocales), - (array) $submissionSubjectDao->getSubjects($article->getCurrentPublication()->getId(), $supportedLocales) + SubmissionKeywordVocab::getKeywords($publication->getId(), $supportedLocales), + SubmissionSubjectVocab::getSubjects($article->getCurrentPublication()->getId(), $supportedLocales) ); $subject = $subjects[$journal->getPrimaryLocale()] ?? ''; diff --git a/plugins/reports/articles/ArticleReportPlugin.php b/plugins/reports/articles/ArticleReportPlugin.php index 1bf75fd89f9..857d32ddb76 100644 --- a/plugins/reports/articles/ArticleReportPlugin.php +++ b/plugins/reports/articles/ArticleReportPlugin.php @@ -18,16 +18,15 @@ use APP\decision\Decision; use APP\facades\Repo; -use PKP\db\DAORegistry; use PKP\facades\Locale; use PKP\plugins\ReportPlugin; use PKP\security\Role; use PKP\stageAssignment\StageAssignment; use PKP\submission\PKPSubmission; use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineDAO; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; +use PKP\submission\SubmissionDisciplineVocab; +use PKP\submission\SubmissionKeywordVocab; +use PKP\submission\SubmissionSubjectVocab; class ArticleReportPlugin extends ReportPlugin { @@ -85,10 +84,6 @@ public function display($args, $request) // Add BOM (byte order mark) to fix UTF-8 in Excel fprintf($fp, chr(0xEF) . chr(0xBB) . chr(0xBF)); - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */ - $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */ - $submissionDisciplineDao = DAORegistry::getDAO('SubmissionDisciplineDAO'); /** @var SubmissionDisciplineDAO $submissionDisciplineDao */ - $userGroups = Repo::userGroup()->getCollector() ->filterByContextIds([$context->getId()]) ->getMany() @@ -158,9 +153,9 @@ public function display($args, $request) $sectionTitles[$sectionId] = $section->getLocalizedTitle(); } - $subjects = $submissionSubjectDao->getSubjects($submission->getCurrentPublication()->getId()); - $disciplines = $submissionDisciplineDao->getDisciplines($submission->getCurrentPublication()->getId()); - $keywords = $submissionKeywordDao->getKeywords($submission->getCurrentPublication()->getId()); + $subjects = SubmissionSubjectVocab::getSubjects($submission->getCurrentPublication()->getId()); + $disciplines = SubmissionDisciplineVocab::getDisciplines($submission->getCurrentPublication()->getId()); + $keywords = SubmissionKeywordVocab::getKeywords($submission->getCurrentPublication()->getId()); $agencies = SubmissionAgencyVocab::getAgencies($submission->getCurrentPublication()->getId()); // Store the submission results diff --git a/tools/cleanReviewerInterests.php b/tools/cleanReviewerInterests.php index e395dac777b..c3375d0af0e 100755 --- a/tools/cleanReviewerInterests.php +++ b/tools/cleanReviewerInterests.php @@ -3,8 +3,8 @@ /** * @file tools/cleanReviewerInterests.php * - * Copyright (c) 2014-2021 Simon Fraser University - * Copyright (c) 2003-2021 John Willinsky + * Copyright (c) 2014-2024 Simon Fraser University + * Copyright (c) 2003-2024 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class ReviewerInterestsDeletionTool @@ -17,10 +17,10 @@ require(dirname(__FILE__) . '/bootstrap.php'); use PKP\cliTool\CommandLineTool; -use PKP\controlledVocab\ControlledVocabDAO; +use PKP\controlledVocab\ControlledVocab; use PKP\controlledVocab\ControlledVocabEntryDAO; use PKP\db\DAORegistry; -use PKP\user\InterestDAO; +use PKP\user\UserInterest; class ReviewerInterestsDeletionTool extends CommandLineTool { @@ -57,7 +57,7 @@ public function usage() /** * Remove user interests that are not referenced by any user account */ - public function execute() + public function execute(): void { $orphans = $this->_getOrphanVocabInterests(); if (!count($orphans)) { @@ -69,7 +69,7 @@ public function execute() switch ($command) { case '--show': $interests = array_map(function ($entry) { - return $entry->getData(InterestDAO::CONTROLLED_VOCAB_INTEREST); + return $entry->getData(UserInterest::CONTROLLED_VOCAB_INTEREST); }, $orphans); echo "Below are the user interests that are not referenced by any user account.\n"; echo "\t" . join("\n\t", $interests) . "\n"; @@ -96,33 +96,23 @@ public function execute() * * @return array array of ControlledVocabEntry object */ - protected function _getOrphanVocabInterests() + protected function _getOrphanVocabInterests(): array { - /** @var InterestDAO */ - $interestDao = DAORegistry::getDAO('InterestDAO'); - /** @var ControlledVocabDAO */ - $vocabDao = DAORegistry::getDAO('ControlledVocabDAO'); - /** @var ControlledVocabEntryDAO */ + /** @var ControlledVocabEntryDAO $vocabEntryDao */ $vocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO'); - - $interestVocab = $vocabDao->getBySymbolic(InterestDAO::CONTROLLED_VOCAB_INTEREST); - $vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->getId()); + $interestVocab = ControlledVocab::withSymbolic(UserInterest::CONTROLLED_VOCAB_INTEREST) + ->withAssoc(0, 0) + ->first(); + $vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->id); $vocabEntryList = $vocabEntryIterator->toArray(); // list of vocab interests in db - $allInterestVocabIds = array_map( - function ($entry) { - return $entry->getId(); - }, - $vocabEntryList - ); + $allInterestVocabIds = array_map(fn ($entry) => $entry->getId(), $vocabEntryList); // list of vocabs associated to users - $interests = $interestDao->getAllInterests(); + $interests = UserInterest::getAllInterests(); $userInterestVocabIds = array_map( - function ($interest) { - return $interest->getId(); - }, + fn ($interest) => $interest->getId(), $interests->toArray() );