From d1d465dbcd52dd02e83ac6bfbab04cc40c716bc5 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 9 Oct 2024 14:40:19 +0600 Subject: [PATCH] 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 827d0fe75d..75669d6b63 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; use PKP\userGroup\UserGroup; @@ -320,9 +320,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 1148738c9b..3fe4e13f72 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -136,6 +136,7 @@ + diff --git a/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php b/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php index 1b8425e50f..627a32ec42 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