From d1e3e38d27644237ad21ba99287c2715d9cdbeda Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Fri, 16 Aug 2024 17:55:11 +0600 Subject: [PATCH] pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model --- api/v1/vocabs/PKPVocabController.php | 4 +- .../forms/publication/PKPMetadataForm.php | 4 +- classes/controlledVocab/ControlledVocab.php | 129 +++++++++------- classes/controlledVocab/Repository.php | 127 ++++++++++++++++ classes/core/PKPApplication.php | 2 - classes/facades/Repo.php | 6 + classes/publication/DAO.php | 13 +- classes/submission/SubmissionAgencyDAO.php | 139 ------------------ classes/submission/SubmissionAgencyVocab.php | 78 ++++++++++ .../validation/ValidatorControlledVocab.php | 36 ++--- .../filter/NativeXmlPKPPublicationFilter.php | 6 +- .../filter/PKPPublicationNativeXmlFilter.php | 6 +- tests/classes/publication/PublicationTest.php | 3 +- 13 files changed, 317 insertions(+), 236 deletions(-) create mode 100644 classes/controlledVocab/Repository.php delete mode 100644 classes/submission/SubmissionAgencyDAO.php create mode 100644 classes/submission/SubmissionAgencyVocab.php diff --git a/api/v1/vocabs/PKPVocabController.php b/api/v1/vocabs/PKPVocabController.php index a35e10927dd..133f2addb32 100644 --- a/api/v1/vocabs/PKPVocabController.php +++ b/api/v1/vocabs/PKPVocabController.php @@ -31,7 +31,7 @@ use PKP\security\authorization\ContextAccessPolicy; use PKP\security\authorization\UserRolesRequiredPolicy; use PKP\security\Role; -use PKP\submission\SubmissionAgencyDAO; +use PKP\submission\SubmissionAgencyVocab; use PKP\submission\SubmissionDisciplineDAO; use PKP\submission\SubmissionKeywordDAO; use PKP\submission\SubmissionSubjectDAO; @@ -126,7 +126,7 @@ public function getMany(Request $illuminateRequest): JsonResponse $submissionDisciplineEntryDao = DAORegistry::getDAO('SubmissionDisciplineEntryDAO'); /** @var \PKP\submission\SubmissionDisciplineEntryDAO $submissionDisciplineEntryDao */ $entries = $submissionDisciplineEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray(); break; - case SubmissionAgencyDAO::CONTROLLED_VOCAB_SUBMISSION_AGENCY: + case SubmissionAgencyVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY: $submissionAgencyEntryDao = DAORegistry::getDAO('SubmissionAgencyEntryDAO'); /** @var \PKP\submission\SubmissionAgencyEntryDAO $submissionAgencyEntryDao */ $entries = $submissionAgencyEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray(); break; diff --git a/classes/components/forms/publication/PKPMetadataForm.php b/classes/components/forms/publication/PKPMetadataForm.php index b5929b797d9..ae65c61ce6b 100644 --- a/classes/components/forms/publication/PKPMetadataForm.php +++ b/classes/components/forms/publication/PKPMetadataForm.php @@ -21,7 +21,7 @@ use PKP\components\forms\FieldText; use PKP\components\forms\FormComponent; use PKP\context\Context; -use PKP\submission\SubmissionAgencyDAO; +use PKP\submission\SubmissionAgencyVocab; use PKP\submission\SubmissionDisciplineDAO; use PKP\submission\SubmissionKeywordDAO; use PKP\submission\SubmissionSubjectDAO; @@ -88,7 +88,7 @@ public function __construct(string $action, array $locales, Publication $publica 'label' => __('submission.supportingAgencies'), 'tooltip' => __('manager.setup.metadata.agencies.description'), 'isMultilingual' => true, - 'apiUrl' => str_replace('__vocab__', SubmissionAgencyDAO::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $suggestionUrlBase), + 'apiUrl' => str_replace('__vocab__', SubmissionAgencyVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $suggestionUrlBase), 'locales' => $this->locales, 'value' => (array) $publication->getData('supportingAgencies'), ])); diff --git a/classes/controlledVocab/ControlledVocab.php b/classes/controlledVocab/ControlledVocab.php index b481d614e56..c1afdf7b9e0 100644 --- a/classes/controlledVocab/ControlledVocab.php +++ b/classes/controlledVocab/ControlledVocab.php @@ -6,103 +6,130 @@ /** * @file classes/controlledVocab/ControlledVocab.php * - * Copyright (c) 2014-2021 Simon Fraser University - * Copyright (c) 2000-2021 John Willinsky + * Copyright (c) 2024 Simon Fraser University + * Copyright (c) 2024 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class ControlledVocab * - * @ingroup controlled_vocab - * - * @see ControlledVocabDAO - * - * @brief Basic class describing an controlled vocab. + * @brief */ namespace PKP\controlledVocab; -use PKP\db\DAORegistry; +use Eloquence\Behaviours\HasCamelCasing; +use Illuminate\Database\Query\JoinClause; +use Illuminate\Support\Facades\DB; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Database\Eloquent\Builder; +use PKP\facades\Locale; -class ControlledVocab extends \PKP\core\DataObject +class ControlledVocab extends Model { - // - // Get/set methods - // + use HasCamelCasing; - /** - * get assoc id - * - * @return int - */ - public function getAssocId() + protected $table = 'controlled_vocabs'; + protected $primaryKey = 'controlled_vocab_id'; + + protected $guarded = [ + 'controlled_vocab_id', + ]; + + protected function casts(): array { - return $this->getData('assocId'); + return [ + 'symbolic' => 'string', + 'assoc_type' => 'integer', + 'assoc_id' => 'integer', + ]; } /** - * set assoc id - * - * @param int $assocId + * Accessor and Mutator for primary key => id */ - public function setAssocId($assocId) + protected function id(): Attribute { - $this->setData('assocId', $assocId); + return Attribute::make( + get: fn($value, $attributes) => $attributes[$this->primaryKey] ?? null, + set: fn($value) => [$this->primaryKey => $value], + ); } /** - * Get associated type. + * Compatibility function for including note IDs in grids. * - * @return int + * @deprecated 3.5.0 Use $model->id instead. Can be removed once the DataObject pattern is removed. */ - public function getAssocType() + public function getId(): int { - return $this->getData('assocType'); + return $this->id; } /** - * Set associated type. + * Compatibility function for including notes in grids. * - * @param int $assocType + * @deprecated 3.5. Use $model or $model->$field instead. Can be removed once the DataObject pattern is removed. */ - public function setAssocType($assocType) + public function getData(?string $field): mixed { - $this->setData('assocType', $assocType); + return $field ? $this->$field : $this; } /** - * Get symbolic name. - * - * @return string + * Scope a query to only include notes with a specific user ID. */ - public function getSymbolic() + public function scopeWithSymbolic(Builder $query, string $symbolic): Builder { - return $this->getData('symbolic'); + return $query->where(DB::raw('lower(symbolic)'), strtolower($symbolic)); } /** - * Set symbolic name. - * - * @param string $symbolic + * Scope a query to only include notes with a specific assoc type and assoc ID. */ - public function setSymbolic($symbolic) + public function scopeWithAssoc(Builder $query, int $assocType, int $assocId): Builder { - $this->setData('symbolic', $symbolic); + return $query + ->where('assoc_type', $assocType) + ->where('assoc_id', $assocId); } /** * Get a list of controlled vocabulary options. * * @param string $settingName optional - * * @return array $controlledVocabEntryId => name */ - public function enumerate($settingName = 'name') - { - $controlledVocabDao = DAORegistry::getDAO('ControlledVocabDAO'); /** @var ControlledVocabDAO $controlledVocabDao */ - return $controlledVocabDao->enumerate($this->getId(), $settingName); + public function enumerate(string $settingName = 'name'): array + { + return DB::table('controlled_vocab_entries AS e') + ->leftJoin('controlled_vocab_entry_settings AS l', fn (JoinClause $join) => $join + ->on('l.controlled_vocab_entry_id', '=', 'e.controlled_vocab_entry_id') + ->where('l.setting_name', '=', $settingName) + ->where('l.locale', '=', Locale::getLocale()) + ) + ->leftJoin('controlled_vocab_entry_settings AS p', fn (JoinClause $join) => $join + ->on('p.controlled_vocab_entry_id', '=', 'e.controlled_vocab_entry_id') + ->where('p.setting_name', '=', $settingName) + ->where('p.locale', '=', Locale::getPrimaryLocale()) + ) + ->leftJoin('controlled_vocab_entry_settings AS n', fn (JoinClause $join) => $join + ->on('n.controlled_vocab_entry_id', '=', 'e.controlled_vocab_entry_id') + ->where('n.setting_name', '=', $settingName) + ->where('n.locale', '=', '') + ) + ->select([ + 'e.controlled_vocab_entry_id', + DB::raw( + 'coalesce (l.setting_value, p.setting_value, n.setting_value) as setting_value' + ), + DB::raw( + 'coalesce (l.setting_type, p.setting_type, n.setting_type) as setting_type' + ), + ]) + ->where('e.controlled_vocab_id', '=', $this->id) + ->get() + ->pluck('setting_value', 'controlled_vocab_entry_id') + ->toArray(); } } - -if (!PKP_STRICT_MODE) { - class_alias('\PKP\controlledVocab\ControlledVocab', '\ControlledVocab'); -} diff --git a/classes/controlledVocab/Repository.php b/classes/controlledVocab/Repository.php new file mode 100644 index 00000000000..cc8c5ab07bf --- /dev/null +++ b/classes/controlledVocab/Repository.php @@ -0,0 +1,127 @@ +withAssoc($assocType, $assocId) + ->firstOr(fn() => ControlledVocab::create([ + 'assocType' => $assocType, + 'assocId' => $assocId, + 'symbolic' => $symbolic, + ])); + } + + /** + * Return the Controlled Vocab Entry DAO for this Controlled Vocab. + * Can be subclassed to provide extended DAOs. + * + * Will be removed once the eloquent based settings table relations task completes. + */ + public function getEntryDAO(): ControlledVocabEntryDAO + { + return DAORegistry::getDAO('ControlledVocabEntryDAO'); + } + + public function getEntryDaoBySymbolic(string $symbolic): ControlledVocabEntryDAO + { + return DAORegistry::getDAO(ucfirst($symbolic) . 'EntryDAO'); + } + + public function getBySymbolic( + string $symbolic, + int $assocType, + int $assocId, + array $locales = [], + ?string $entryDaoClassName = null): array + { + $result = []; + + $controlledVocab = $this->build($symbolic, $assocType, $assocId); + + /** @var ControlledVocabEntryDAO $entryDao */ + $entryDao = $entryDaoClassName + ? DAORegistry::getDAO($entryDaoClassName) + : $this->getEntryDaoBySymbolic($symbolic); + + $controlledVocabEntries = $entryDao->getByControlledVocabId($controlledVocab->id); + + while ($vocabEntry = $controlledVocabEntries->next()) { + $vocabs = $vocabEntry->getData($symbolic); + foreach ($vocabs as $locale => $value) { + if (empty($locales) || in_array($locale, $locales)) { + $result[$locale][] = $value; + } + } + } + + return $result; + } + + /** + * Get an array of all of the vocabs for given symbolic + */ + public function getAllUniqueBySymbolic(string $symbolic): array + { + return DB::table('controlled_vocab_entry_settings') + ->select('setting_value') + ->where('setting_name', $symbolic) + ->distinct() + ->get() + ->pluck('setting_value') + ->toArray(); + } + + /** + * Add an array of vocabs + */ + public function insertBySymbolic( + string $symbolic, + array $vocabs, + int $assocType, + int $assocId, + bool $deleteFirst = true, + ?string $entryDaoClassName = null): void + { + /** @var ControlledVocabEntryDAO $entryDao */ + $entryDao = $entryDaoClassName + ? DAORegistry::getDAO($entryDaoClassName) + : $this->getEntryDaoBySymbolic($symbolic); + + $currentControlledVocab = $this->build($symbolic, $assocType, $assocId); + + if ($deleteFirst) { + collect($currentControlledVocab->enumerate( $symbolic)) + ->keys() + ->each(fn (int $id) => $entryDao->deleteObjectById($id)); + } + + if (is_array($vocabs)) { // localized, array of arrays + foreach ($vocabs as $locale => $list) { + if (is_array($list)) { + $list = array_unique($list); // Remove any duplicate keywords + $i = 1; + foreach ($list as $vocab) { + $vocabEntry = $entryDao->newDataObject(); + $vocabEntry->setControlledVocabId($currentControlledVocab->id); + $vocabEntry->setData($symbolic, $vocab, $locale); + $vocabEntry->setSequence($i); + $i++; + $entryDao->insertObject($vocabEntry); + } + } + } + } + } +} diff --git a/classes/core/PKPApplication.php b/classes/core/PKPApplication.php index e02dd22d551..1cf24d11fa3 100644 --- a/classes/core/PKPApplication.php +++ b/classes/core/PKPApplication.php @@ -473,7 +473,6 @@ public function getDAOMap() return [ 'AnnouncementTypeDAO' => 'PKP\announcement\AnnouncementTypeDAO', 'CitationDAO' => 'PKP\citation\CitationDAO', - 'ControlledVocabDAO' => 'PKP\controlledVocab\ControlledVocabDAO', 'ControlledVocabEntryDAO' => 'PKP\controlledVocab\ControlledVocabEntryDAO', 'DataObjectTombstoneDAO' => 'PKP\tombstone\DataObjectTombstoneDAO', 'DataObjectTombstoneSettingsDAO' => 'PKP\tombstone\DataObjectTombstoneSettingsDAO', @@ -499,7 +498,6 @@ public function getDAOMap() 'RoleDAO' => 'PKP\security\RoleDAO', 'SiteDAO' => 'PKP\site\SiteDAO', 'SubEditorsDAO' => 'PKP\context\SubEditorsDAO', - 'SubmissionAgencyDAO' => 'PKP\submission\SubmissionAgencyDAO', 'SubmissionAgencyEntryDAO' => 'PKP\submission\SubmissionAgencyEntryDAO', 'SubmissionCommentDAO' => 'PKP\submission\SubmissionCommentDAO', 'SubmissionDisciplineDAO' => 'PKP\submission\SubmissionDisciplineDAO', diff --git a/classes/facades/Repo.php b/classes/facades/Repo.php index cbfb448f7d1..2996c814cab 100644 --- a/classes/facades/Repo.php +++ b/classes/facades/Repo.php @@ -27,6 +27,7 @@ use PKP\announcement\Repository as AnnouncementRepository; use PKP\author\Repository as AuthorRepository; use PKP\category\Repository as CategoryRepository; +use PKP\controlledVocab\Repository as ControlledVocabRepository; use PKP\decision\Repository as DecisionRepository; use PKP\emailTemplate\Repository as EmailTemplateRepository; use PKP\highlight\Repository as HighlightRepository; @@ -134,4 +135,9 @@ public static function note(): NoteRepository { return app(NoteRepository::class); } + + public static function controlledVocab(): ControlledVocabRepository + { + return app(ControlledVocabRepository::class); + } } diff --git a/classes/publication/DAO.php b/classes/publication/DAO.php index 3bfececa21d..7b4a49e782f 100644 --- a/classes/publication/DAO.php +++ b/classes/publication/DAO.php @@ -23,7 +23,7 @@ use PKP\core\EntityDAO; use PKP\core\traits\EntityWithParent; use PKP\services\PKPSchemaService; -use PKP\submission\SubmissionAgencyDAO; +use PKP\submission\SubmissionAgencyVocab; use PKP\submission\SubmissionDisciplineDAO; use PKP\submission\SubmissionKeywordDAO; use PKP\submission\SubmissionSubjectDAO; @@ -58,9 +58,6 @@ class DAO extends EntityDAO /** @var SubmissionDisciplineDAO */ public $submissionDisciplineDao; - /** @var SubmissionAgencyDAO */ - public $submissionAgencyDao; - /** @var CitationDAO */ public $citationDao; @@ -71,7 +68,6 @@ public function __construct( SubmissionKeywordDAO $submissionKeywordDao, SubmissionSubjectDAO $submissionSubjectDao, SubmissionDisciplineDAO $submissionDisciplineDao, - SubmissionAgencyDAO $submissionAgencyDao, CitationDAO $citationDao, PKPSchemaService $schemaService ) { @@ -80,7 +76,6 @@ public function __construct( $this->submissionKeywordDao = $submissionKeywordDao; $this->submissionSubjectDao = $submissionSubjectDao; $this->submissionDisciplineDao = $submissionDisciplineDao; - $this->submissionAgencyDao = $submissionAgencyDao; $this->citationDao = $citationDao; } @@ -373,7 +368,7 @@ protected function setControlledVocab(Publication $publication) $publication->setData('keywords', $this->submissionKeywordDao->getKeywords($publication->getId())); $publication->setData('subjects', $this->submissionSubjectDao->getSubjects($publication->getId())); $publication->setData('disciplines', $this->submissionDisciplineDao->getDisciplines($publication->getId())); - $publication->setData('supportingAgencies', $this->submissionAgencyDao->getAgencies($publication->getId())); + $publication->setData('supportingAgencies', SubmissionAgencyVocab::getAgencies($publication->getId())); } /** @@ -421,7 +416,7 @@ protected function saveControlledVocab(array $values, int $publicationId) $this->submissionDisciplineDao->insertDisciplines($value, $publicationId); break; case 'supportingAgencies': - $this->submissionAgencyDao->insertAgencies($value, $publicationId); + SubmissionAgencyVocab::insertAgencies($value, $publicationId); break; } } @@ -435,7 +430,7 @@ protected function deleteControlledVocab(int $publicationId) $this->submissionKeywordDao->insertKeywords([], $publicationId); $this->submissionSubjectDao->insertSubjects([], $publicationId); $this->submissionDisciplineDao->insertDisciplines([], $publicationId); - $this->submissionAgencyDao->insertAgencies([], $publicationId); + SubmissionAgencyVocab::insertAgencies([], $publicationId); } /** diff --git a/classes/submission/SubmissionAgencyDAO.php b/classes/submission/SubmissionAgencyDAO.php deleted file mode 100644 index 44e6861bf8d..00000000000 --- a/classes/submission/SubmissionAgencyDAO.php +++ /dev/null @@ -1,139 +0,0 @@ -build($publicationId, $assocType); - $submissionAgencyEntryDao = DAORegistry::getDAO('SubmissionAgencyEntryDAO'); /** @var SubmissionAgencyEntryDAO $submissionAgencyEntryDao */ - $submissionAgencies = $submissionAgencyEntryDao->getByControlledVocabId($agencies->getId()); - while ($agencyEntry = $submissionAgencies->next()) { - $agency = $agencyEntry->getAgency(); - foreach ($agency as $locale => $value) { - if (empty($locales) || in_array($locale, $locales)) { - $result[$locale][] = $value; - } - } - } - - return $result; - } - - /** - * Get an array of all of the submission's agencies - * - * @return array - */ - public function getAllUniqueAgencies() - { - $result = $this->retrieve('SELECT DISTINCT setting_value FROM controlled_vocab_entry_settings WHERE setting_name = ?', [self::CONTROLLED_VOCAB_SUBMISSION_AGENCY]); - - $agencies = []; - foreach ($result as $row) { - $agencies[] = $row->setting_value; - } - return $agencies; - } - - /** - * Add an array of agencies - * - * @param array $agencies List of agencies. - * @param int $publicationId Submission ID. - * @param bool $deleteFirst True iff existing agencies should be removed first. - * @param int $assocType DO NOT USE: For <3.1 to 3.x migration pkp/pkp-lib#3572 pkp/pkp-lib#6213 - */ - public function insertAgencies($agencies, $publicationId, $deleteFirst = true, $assocType = PKPApplication::ASSOC_TYPE_PUBLICATION) - { - $agencyDao = DAORegistry::getDAO('SubmissionAgencyDAO'); /** @var SubmissionAgencyDAO $agencyDao */ - $submissionAgencyEntryDao = DAORegistry::getDAO('SubmissionAgencyEntryDAO'); /** @var SubmissionAgencyEntryDAO $submissionAgencyEntryDao */ - $currentAgencies = $this->build($publicationId, $assocType); - - if ($deleteFirst) { - $existingEntries = $agencyDao->enumerate($currentAgencies->getId(), self::CONTROLLED_VOCAB_SUBMISSION_AGENCY); - - foreach ($existingEntries as $id => $entry) { - $entry = trim($entry); - $submissionAgencyEntryDao->deleteObjectById($id); - } - } - if (is_array($agencies)) { // localized, array of arrays - foreach ($agencies as $locale => $list) { - if (is_array($list)) { - $list = array_unique($list); // Remove any duplicate keywords - $i = 1; - foreach ($list as $agency) { - $agencyEntry = $submissionAgencyEntryDao->newDataObject(); - $agencyEntry->setControlledVocabId($currentAgencies->getId()); - $agencyEntry->setAgency($agency, $locale); - $agencyEntry->setSequence($i); - $i++; - $submissionAgencyEntryDao->insertObject($agencyEntry); - } - } - } - } - } -} - -if (!PKP_STRICT_MODE) { - class_alias('\PKP\submission\SubmissionAgencyDAO', '\SubmissionAgencyDAO'); - define('CONTROLLED_VOCAB_SUBMISSION_AGENCY', SubmissionAgencyDAO::CONTROLLED_VOCAB_SUBMISSION_AGENCY); -} diff --git a/classes/submission/SubmissionAgencyVocab.php b/classes/submission/SubmissionAgencyVocab.php new file mode 100644 index 00000000000..8a83d54ef63 --- /dev/null +++ b/classes/submission/SubmissionAgencyVocab.php @@ -0,0 +1,78 @@ +getBySymbolic( + static::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + $assocType, + $publicationId, + $locales + ); + } + + /** + * Get an array of all of the submission's agencies + */ + public function scoprGetAllUniqueAgencies():array + { + return Repo::controlledVocab()->getAllUniqueBySymbolic( + static::CONTROLLED_VOCAB_SUBMISSION_AGENCY + ); + } + + /** + * Add an array of agencies + * + * @param array $agencies List of agencies. + * @param int $publicationId Submission ID. + * @param bool $deleteFirst True iff existing agencies should be removed first. + * @param int $assocType DO NOT USE: For <3.1 to 3.x migration pkp/pkp-lib#3572 pkp/pkp-lib#6213 + */ + public function scoprInsertAgencies(array $agencies, int $publicationId, bool $deleteFirst = true, int $assocType = PKPApplication::ASSOC_TYPE_PUBLICATION): void + { + Repo::controlledVocab()->insertBySymbolic( + static::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + $agencies, + $assocType, + $publicationId, + $deleteFirst + ); + } +} diff --git a/classes/validation/ValidatorControlledVocab.php b/classes/validation/ValidatorControlledVocab.php index 935d486e3f0..93600854a53 100644 --- a/classes/validation/ValidatorControlledVocab.php +++ b/classes/validation/ValidatorControlledVocab.php @@ -17,45 +17,35 @@ namespace PKP\validation; -use PKP\controlledVocab\ControlledVocabDAO; -use PKP\db\DAORegistry; +use PKP\controlledVocab\ControlledVocab; class ValidatorControlledVocab extends Validator { - /** @var array */ - public $_acceptedValues; + public array $acceptedValues; /** - * Constructor. - * - * @param string $symbolic - * @param int $assocType - * @param int $assocId + * Constructor */ - public function __construct($symbolic, $assocType, $assocId) + public function __construct(string $symbolic, int $assocType, int $assocId) { - $controlledVocabDao = DAORegistry::getDAO('ControlledVocabDAO'); /** @var ControlledVocabDAO $controlledVocabDao */ - $controlledVocab = $controlledVocabDao->getBySymbolic($symbolic, $assocType, $assocId); - if ($controlledVocab) { - $this->_acceptedValues = array_keys($controlledVocab->enumerate()); - } else { - $this->_acceptedValues = []; - } + $controlledVocab = ControlledVocab::withSymbolic($symbolic) + ->withAssoc($assocType, $assocId) + ->first(); + + $this->acceptedValues = $controlledVocab?->enumerate() ?? []; } - // // Implement abstract methods from Validator // + /** - * @see Validator::isValid() * Value is valid if it is empty and optional or is in the set of accepted values. - * - * @return bool + * @see Validator::isValid() */ - public function isValid($value) + public function isValid($value): bool { - return in_array($value, $this->_acceptedValues); + return in_array($value, $this->acceptedValues); } } diff --git a/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php b/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php index 0149f9fab33..dc0af8d14dc 100644 --- a/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php +++ b/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php @@ -138,7 +138,7 @@ public function handleChildElement($n, $publication) if (in_array($n->tagName, $setterMappings)) { $publication->setData($n->tagName, $value, $locale); } elseif (isset($controlledVocabulariesMappings[$n->tagName])) { - $controlledVocabulariesDao = $submissionKeywordDao = DAORegistry::getDAO($controlledVocabulariesMappings[$n->tagName][0]); + $controlledVocabulariesModel = $submissionKeywordModel = $controlledVocabulariesMappings[$n->tagName][0]; $insertFunction = $controlledVocabulariesMappings[$n->tagName][1]; $controlledVocabulary = []; @@ -151,7 +151,7 @@ public function handleChildElement($n, $publication) $controlledVocabulariesValues = []; $controlledVocabulariesValues[$locale] = $controlledVocabulary; - $controlledVocabulariesDao->$insertFunction($controlledVocabulariesValues, $publication->getId(), false); + $controlledVocabulariesModel::$insertFunction($controlledVocabulariesValues, $publication->getId(), false); $publicationNew = Repo::publication()->get($publication->getId()); $publication->setData($n->tagName, $publicationNew->getData($n->tagName)); @@ -316,7 +316,7 @@ public function _getControlledVocabulariesMappings() { return [ 'keywords' => ['SubmissionKeywordDAO', 'insertKeywords'], - 'agencies' => ['SubmissionAgencyDAO', 'insertAgencies'], + 'agencies' => ['SubmissionAgencyVocab', 'insertAgencies'], 'disciplines' => ['SubmissionDisciplineDAO', 'insertDisciplines'], 'subjects' => ['SubmissionSubjectDAO', 'insertSubjects'], ]; diff --git a/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php b/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php index 30a902e67d6..ced091e7c89 100644 --- a/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php +++ b/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php @@ -216,10 +216,10 @@ public function addMetadata($doc, $entityNode, $entity) $supportedLocales = $deployment->getContext()->getSupportedFormLocales(); $controlledVocabulariesMapping = $this->_getControlledVocabulariesMappings(); foreach ($controlledVocabulariesMapping as $controlledVocabulariesNodeName => $mappings) { - $dao = DAORegistry::getDAO($mappings[0]); + $vocabModel = $mappings[0]; $getFunction = $mappings[1]; $controlledVocabularyNodeName = $mappings[2]; - $controlledVocabulary = $dao->$getFunction($entity->getId(), $supportedLocales); + $controlledVocabulary = $vocabModel::$getFunction($entity->getId(), $supportedLocales); $this->addControlledVocabulary($doc, $entityNode, $controlledVocabulariesNodeName, $controlledVocabularyNodeName, $controlledVocabulary); } } @@ -305,7 +305,7 @@ public function _getControlledVocabulariesMappings() { return [ 'keywords' => ['SubmissionKeywordDAO', 'getKeywords', 'keyword'], - 'agencies' => ['SubmissionAgencyDAO', 'getAgencies', 'agency'], + 'agencies' => ['SubmissionAgencyVocab', 'getAgencies', 'agency'], 'disciplines' => ['SubmissionDisciplineDAO', 'getDisciplines', 'discipline'], 'subjects' => ['SubmissionSubjectDAO', 'getSubjects', 'subject'], ]; diff --git a/tests/classes/publication/PublicationTest.php b/tests/classes/publication/PublicationTest.php index 5e57895f00d..d6f329f5f58 100644 --- a/tests/classes/publication/PublicationTest.php +++ b/tests/classes/publication/PublicationTest.php @@ -21,7 +21,7 @@ use APP\publication\Publication; use PKP\citation\CitationDAO; use PKP\services\PKPSchemaService; -use PKP\submission\SubmissionAgencyDAO; +use PKP\submission\SubmissionAgencyVocab; use PKP\submission\SubmissionDisciplineDAO; use PKP\submission\SubmissionKeywordDAO; use PKP\submission\SubmissionSubjectDAO; @@ -43,7 +43,6 @@ protected function setUp(): void new SubmissionKeywordDAO(), new SubmissionSubjectDAO(), new SubmissionDisciplineDAO(), - new SubmissionAgencyDAO(), new CitationDAO(), new PKPSchemaService() ))->newDataObject();