From 88497ae8058c748b4ef39717ad6e9ca4352d6f4a Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 9 Oct 2024 14:40:19 +0600 Subject: [PATCH 1/3] pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model --- classes/search/PreprintSearch.php | 13 +++++--- dbscripts/xml/upgrade.xml | 1 + .../dc11/filter/Dc11SchemaPreprintAdapter.php | 21 +++++++----- .../dc/tests/OAIMetadataFormat_DCTest.php | 33 +++++++++---------- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/classes/search/PreprintSearch.php b/classes/search/PreprintSearch.php index 500a8d70dc..c86b3c0e0b 100644 --- a/classes/search/PreprintSearch.php +++ b/classes/search/PreprintSearch.php @@ -23,12 +23,12 @@ use APP\core\Request; use APP\facades\Repo; use APP\server\Server; +use PKP\controlledVocab\ControlledVocab; use PKP\db\DAORegistry; use PKP\facades\Locale; use PKP\plugins\Hook; use PKP\search\SubmissionSearch; use PKP\submission\PKPSubmission; -use PKP\submission\SubmissionKeywordDAO; use PKP\user\User; class PreprintSearch extends SubmissionSearch @@ -318,9 +318,14 @@ public function getSimilarityTerms($submissionId) $preprint = Repo::submission()->get($submissionId); if ($preprint->getData('status') === PKPSubmission::STATUS_PUBLISHED) { // Retrieve keywords (if any). - /** @var SubmissionKeywordDAO */ - $submissionSubjectDao = DAORegistry::getDAO('SubmissionKeywordDAO'); - $allSearchTerms = array_filter($submissionSubjectDao->getKeywords($preprint->getId(), [Locale::getLocale(), $preprint->getData('locale'), Locale::getPrimaryLocale()])); + $allSearchTerms = array_filter( + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, + Application::ASSOC_TYPE_PUBLICATION, + $preprint->getId(), + [Locale::getLocale(), $preprint->getData('locale'), Locale::getPrimaryLocale()] + ) + ); foreach ($allSearchTerms as $locale => $localeSearchTerms) { $searchTerms += $localeSearchTerms; } diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index fee2411b53..255020e40f 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -131,6 +131,7 @@ + diff --git a/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php b/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php index 884e8c00d9..32433f256e 100644 --- a/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php +++ b/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php @@ -26,14 +26,13 @@ use APP\oai\ops\OAIDAO; use APP\plugins\PubIdPlugin; use APP\submission\Submission; +use PKP\controlledVocab\ControlledVocab; use PKP\db\DAORegistry; use PKP\facades\Locale; use PKP\metadata\MetadataDataObjectAdapter; use PKP\metadata\MetadataDescription; use PKP\plugins\Hook; use PKP\plugins\PluginRegistry; -use PKP\submission\SubmissionKeywordDAO; -use PKP\submission\SubmissionSubjectDAO; class Dc11SchemaPreprintAdapter extends MetadataDataObjectAdapter { @@ -88,14 +87,20 @@ public function &extractMetadataFromDataObject(&$submission) } // Subject - /** @var SubmissionKeywordDAO */ - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); - /** @var SubmissionSubjectDAO */ - $submissionSubjectDao = DAORegistry::getDAO('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/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php index 3db04df7f5..bc14d992fc 100755 --- a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php +++ b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php @@ -35,8 +35,10 @@ use APP\server\Server; use APP\submission\Submission; use Illuminate\Support\LazyCollection; +use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; +use PKP\controlledVocab\Repository as ControlledVocabRepository; use PKP\core\Dispatcher; use PKP\core\Registry; use PKP\db\DAORegistry; @@ -44,8 +46,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)] @@ -57,7 +57,7 @@ class OAIMetadataFormat_DCTest extends PKPTestCase */ protected function getMockedDAOs(): array { - return [...parent::getMockedDAOs(), 'OAIDAO', 'SubmissionSubjectDAO', 'SubmissionKeywordDAO']; + return [...parent::getMockedDAOs(), 'OAIDAO']; } /** @@ -93,6 +93,7 @@ public function testToXml() $publication = $this->getMockBuilder(Publication::class) ->onlyMethods([]) ->getMock(); + $publication->setData('id', 0); $publication->setData('pages', 15); $publication->setData('type', 'art-type', 'en'); $publication->setData('title', 'preprint-title-en', 'en'); @@ -158,6 +159,7 @@ public function testToXml() ->willReturn(Server::PUBLISHING_MODE_OPEN); $server->setName('server-title', 'en'); $server->setData('publisherInstitution', 'server-publisher'); + $server->setData('supportedFormLocales', []); $server->setPrimaryLocale('en'); $server->setPath('server-path'); $server->setData('onlineIssn', 'onlineIssn'); @@ -232,23 +234,18 @@ 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']) + $controlledVocabRepoMock = Mockery::mock(ControlledVocabRepository::class) + ->makePartial() + ->shouldReceive('getBySymbolic') + ->twice() + ->withAnyArgs() + ->andReturn( + ['en' => ['preprint-keyword']], + ['en' => ['preprint-subject', 'preprint-subject-class']] + ) ->getMock(); - $submissionSubjectDao->expects($this->any()) - ->method('getSubjects') - ->willReturn(['en' => ['preprint-subject', 'preprint-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' => ['preprint-keyword']]); - DAORegistry::registerDAO('SubmissionKeywordDAO', $submissionKeywordDao); + app()->instance(ControlledVocabRepository::class, $controlledVocabRepoMock); // // Test From dc72700072681534019f88d2487d40844cefab5d Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 9 Oct 2024 14:40:35 +0600 Subject: [PATCH 2/3] 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 b8d985fb8b..87adda27ed 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit b8d985fb8baebe981935ba2175616c6fd1a923b8 +Subproject commit 87adda27ed35e0cf1b4605bf7402f971de97f6cc diff --git a/plugins/generic/citationStyleLanguage b/plugins/generic/citationStyleLanguage index 90ea703be7..72f5cfb411 160000 --- a/plugins/generic/citationStyleLanguage +++ b/plugins/generic/citationStyleLanguage @@ -1 +1 @@ -Subproject commit 90ea703be706dd5ca6f86993bdb4e6d7be1de53b +Subproject commit 72f5cfb411587712eeca87a9485cd7d2457add5c From 46e9acbb0ce752052de59660a1bdc4ffc57ca045 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Mon, 21 Oct 2024 18:52:56 +0600 Subject: [PATCH 3/3] pkp/pkp-lib#10292 Submodule Update ##touhidurabir/i10292_main## --- lib/pkp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkp b/lib/pkp index 87adda27ed..94653e0ddf 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 87adda27ed35e0cf1b4605bf7402f971de97f6cc +Subproject commit 94653e0ddf818fe2518a02e2ce13238488fa5729