Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model #788

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

class PreprintSearch extends SubmissionSearch
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<migration class="APP\migration\upgrade\v3_5_0\I9937_EditorialTeamToEditorialHistory"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10041_UserGroupsAndUserUserGroupsMastheadValues"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9771_OrcidMigration"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10292_RemoveControlledVocabEntrySettingType"/>
</upgrade>

<!-- update plugin configuration - should be done as the final upgrade task -->
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Submodule pkp updated 54 files
+21 −27 api/v1/vocabs/PKPVocabController.php
+2 −2 classes/components/forms/publication/Details.php
+5 −8 classes/components/forms/publication/PKPMetadataForm.php
+149 −56 classes/controlledVocab/ControlledVocab.php
+0 −274 classes/controlledVocab/ControlledVocabDAO.php
+140 −52 classes/controlledVocab/ControlledVocabEntry.php
+0 −294 classes/controlledVocab/ControlledVocabEntryDAO.php
+135 −0 classes/controlledVocab/Repository.php
+0 −12 classes/core/PKPApplication.php
+58 −4 classes/core/SettingsBuilder.php
+50 −5 classes/core/traits/ModelWithSettings.php
+12 −0 classes/facades/Repo.php
+11 −3 classes/metadata/MetadataProperty.php
+0 −1 classes/migration/install/ControlledVocabMigration.php
+42 −0 classes/migration/upgrade/v3_5_0/I10292_RemoveControlledVocabEntrySettingType.php
+72 −50 classes/publication/DAO.php
+2 −2 classes/services/PKPSchemaService.php
+0 −56 classes/submission/SubmissionAgency.php
+0 −139 classes/submission/SubmissionAgencyDAO.php
+0 −61 classes/submission/SubmissionAgencyEntryDAO.php
+0 −56 classes/submission/SubmissionDiscipline.php
+0 −140 classes/submission/SubmissionDisciplineDAO.php
+0 −61 classes/submission/SubmissionDisciplineEntryDAO.php
+0 −56 classes/submission/SubmissionKeyword.php
+0 −161 classes/submission/SubmissionKeywordDAO.php
+0 −62 classes/submission/SubmissionKeywordEntryDAO.php
+0 −60 classes/submission/SubmissionLanguage.php
+0 −141 classes/submission/SubmissionLanguageDAO.php
+0 −64 classes/submission/SubmissionLanguageEntryDAO.php
+0 −59 classes/submission/SubmissionSubject.php
+0 −141 classes/submission/SubmissionSubjectDAO.php
+0 −61 classes/submission/SubmissionSubjectEntryDAO.php
+0 −163 classes/user/InterestDAO.php
+0 −50 classes/user/InterestEntry.php
+0 −100 classes/user/InterestEntryDAO.php
+0 −105 classes/user/InterestManager.php
+2 −2 classes/user/User.php
+1 −3 classes/user/form/RegistrationForm.php
+2 −6 classes/user/form/RolesForm.php
+144 −0 classes/user/interest/Repository.php
+109 −0 classes/user/interest/UserInterest.php
+8 −13 classes/user/maps/Schema.php
+17 −29 classes/validation/ValidatorControlledVocab.php
+2 −5 controllers/grid/settings/user/form/UserDetailsForm.php
+1 −3 controllers/grid/users/reviewer/form/CreateReviewerForm.php
+2 −2 pages/user/PKPUserHandler.php
+14 −8 plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php
+14 −8 plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php
+1 −3 plugins/importexport/users/filter/PKPUserUserXmlFilter.php
+1 −3 plugins/importexport/users/filter/UserXmlPKPUserFilter.php
+44 −47 tests/classes/form/validation/FormValidatorControlledVocabTest.php
+29 −23 tests/classes/metadata/MetadataPropertyTest.php
+0 −8 tests/classes/publication/PublicationTest.php
+39 −46 tests/classes/validation/ValidatorControlledVocabTest.php
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