Skip to content

Commit

Permalink
pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Dec 21, 2024
1 parent d6e1bac commit d1d465d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
13 changes: 9 additions & 4 deletions classes/search/PreprintSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<migration class="PKP\migration\upgrade\v3_5_0\I9707_WeblateUILocales"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10738_RemoveInvalidUserGroups"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10362_EventLogEditorNames"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10292_RemoveControlledVocabEntrySettingType"/>
</upgrade>

<!-- update plugin configuration - should be done as the final upgrade task -->
Expand Down
21 changes: 13 additions & 8 deletions plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down
33 changes: 15 additions & 18 deletions plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
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;
use PKP\doi\Doi;
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)]
Expand All @@ -57,7 +57,7 @@ class OAIMetadataFormat_DCTest extends PKPTestCase
*/
protected function getMockedDAOs(): array
{
return [...parent::getMockedDAOs(), 'OAIDAO', 'SubmissionSubjectDAO', 'SubmissionKeywordDAO'];
return [...parent::getMockedDAOs(), 'OAIDAO'];
}

/**
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d1d465d

Please sign in to comment.