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 Nov 16, 2024
1 parent 9436bca commit 11d9180
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 77 deletions.
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
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

0 comments on commit 11d9180

Please sign in to comment.