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 #1722

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<migration class="APP\migration\upgrade\v3_5_0\I5885_RenameReviewReminderSettingsName"/>
<migration class="PKP\migration\upgrade\v3_5_0\COA75_AddUserRoleEndEmail"/>
<migration class="APP\migration\upgrade\v3_5_0\I10561_OnixFilter"/>
<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 57 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
+63 −8 classes/core/SettingsBuilder.php
+55 −0 classes/core/casts/MultilingualSettingAttribute.php
+14 −6 classes/core/traits/EntityUpdate.php
+74 −12 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
+56 −130 composer.lock
+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
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
use APP\publicationFormat\PublicationFormat;
use APP\section\Section;
use APP\submission\Submission;
use PKP\controlledVocab\ControlledVocab;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\i18n\LocaleConversion;
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 Dc11SchemaPublicationFormatAdapter extends MetadataDataObjectAdapter
{
Expand Down Expand Up @@ -99,12 +98,20 @@ public function extractMetadataFromDataObject(&$publicationFormat)
}

// Subject
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */
$submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $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
46 changes: 29 additions & 17 deletions plugins/reports/monographReport/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@
use Illuminate\Support\LazyCollection;
use IteratorAggregate;
use PKP\category\Category;
use PKP\db\DAORegistry;
use PKP\controlledVocab\ControlledVocab;
use PKP\facades\Locale;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignment;
use PKP\submission\SubmissionAgencyDAO;
use PKP\submission\SubmissionDisciplineDAO;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;
use PKP\user\User;
use PKP\userGroup\UserGroup;
use Traversable;
Expand Down Expand Up @@ -366,39 +362,55 @@ private function getStatus(): string
*/
private function getKeywords(): string
{
/** @var SubmissionKeywordDAO */
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
return $this->flattenKeywords($submissionKeywordDao->getKeywords($this->publication->getId()));
return $this->flattenKeywords(
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
Application::ASSOC_TYPE_PUBLICATION,
$this->publication->getId()
)
);
}

/**
* Retrieves the subjects separated by commas
*/
private function getSubjects(): string
{
/** @var SubmissionSubjectDAO */
$submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO');
return $this->flattenKeywords($submissionSubjectDao->getSubjects($this->publication->getId()));
return $this->flattenKeywords(
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
Application::ASSOC_TYPE_PUBLICATION,
$this->publication->getId()
)
);
}

/**
* Retrieves the disciplines separated by commas
*/
private function getDisciplines(): string
{
/** @var SubmissionDisciplineDAO */
$submissionDisciplineDao = DAORegistry::getDAO('SubmissionDisciplineDAO');
return $this->flattenKeywords($submissionDisciplineDao->getDisciplines($this->publication->getId()));
return $this->flattenKeywords(
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE,
Application::ASSOC_TYPE_PUBLICATION,
$this->publication->getId()
)
);
}

/**
* Retrieves the agencies separated by commas
*/
private function getAgencies(): string
{
/** @var SubmissionAgencyDAO */
$submissionAgencyDao = DAORegistry::getDAO('SubmissionAgencyDAO');
return $this->flattenKeywords($submissionAgencyDao->getAgencies($this->publication->getId()));
return $this->flattenKeywords(
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
Application::ASSOC_TYPE_PUBLICATION,
$this->publication->getId()
)
);
}

/**
Expand Down
68 changes: 14 additions & 54 deletions tools/cleanReviewerInterests.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* @brief CLI tool to remove user interests that are not referenced by any user accounts.
*/

use APP\facades\Repo;
use Illuminate\Support\Collection;
use PKP\cliTool\CommandLineTool;
use PKP\controlledVocab\ControlledVocabDAO;
use PKP\controlledVocab\ControlledVocabEntryDAO;
use PKP\db\DAORegistry;
use PKP\user\InterestDAO;
use PKP\controlledVocab\ControlledVocabEntry;
use PKP\user\interest\UserInterest;

require(dirname(__FILE__) . '/bootstrap.php');

Expand Down Expand Up @@ -60,28 +60,21 @@ public function usage()
public function execute()
{
$orphans = $this->_getOrphanVocabInterests();
if (!count($orphans)) {
if ($orphans->count() === 0) {
echo "No user interests to remove.\n";
exit(0);
}

$command = $this->parameters[0];
switch ($command) {
case '--show':
$interests = array_map(function ($entry) {
return $entry->getData(InterestDAO::CONTROLLED_VOCAB_INTEREST);
}, $orphans);
$interests = $orphans->pluck(UserInterest::CONTROLLED_VOCAB_INTEREST)->toArray();
echo "Below are the user interests that are not referenced by any user account.\n";
echo "\t" . join("\n\t", $interests) . "\n";
break;

case '--remove':
/** @var ControlledVocabEntryDAO */
$vocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO');
foreach ($orphans as $orphanVocab) {
$vocabEntryDao->deleteObject($orphanVocab);
}
echo count($orphans) . " entries deleted\n";
echo $orphans->toQuery()->delete() . " entries deleted\n";
break;

default:
Expand All @@ -93,50 +86,17 @@ public function execute()

/**
* Returns user interests that are not referenced
*
* @return array array of ControlledVocabEntry object
*/
protected function _getOrphanVocabInterests()
protected function _getOrphanVocabInterests(): Collection
{
/** @var InterestDAO */
$interestDao = DAORegistry::getDAO('InterestDAO');
/** @var ControlledVocabDAO */
$vocabDao = DAORegistry::getDAO('ControlledVocabDAO');
/** @var ControlledVocabEntryDAO */
$vocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO');

$interestVocab = $vocabDao->getBySymbolic(InterestDAO::CONTROLLED_VOCAB_INTEREST);
$vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->getId());
$vocabEntryList = $vocabEntryIterator->toArray();

// list of vocab interests in db
$allInterestVocabIds = array_map(
function ($entry) {
return $entry->getId();
},
$vocabEntryList
);

// list of vocabs associated to users
$interests = $interestDao->getAllInterests();
$userInterestVocabIds = array_map(
function ($interest) {
return $interest->getId();
},
$interests->toArray()
);

// get the difference
$diff = array_diff($allInterestVocabIds, $userInterestVocabIds);

$orphans = array_filter(
$vocabEntryList,
function ($entry) use ($diff) {
return in_array($entry->getId(), $diff);
}
$controlledVocab = Repo::controlledVocab()->build(
UserInterest::CONTROLLED_VOCAB_INTEREST
);

return $orphans;
return ControlledVocabEntry::query()
->withControlledVocabId($controlledVocab->id)
->whereDoesntHave('userInterest')
->get();
}
}

Expand Down