From 4c2b857781aaafa3ca5e76df66e9195ef814331a Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Mon, 26 Aug 2024 19:04:01 +0600 Subject: [PATCH] pkp/pkp-lib#10292 removed extended vocab classes --- api/v1/vocabs/PKPVocabController.php | 33 ++----- .../components/forms/publication/Details.php | 4 +- .../forms/publication/PKPMetadataForm.php | 13 +-- classes/controlledVocab/ControlledVocab.php | 45 ++++++--- classes/publication/DAO.php | 84 +++++++++++++---- classes/submission/SubmissionAgencyVocab.php | 90 ------------------ .../submission/SubmissionDisciplineVocab.php | 92 ------------------ classes/submission/SubmissionKeywordVocab.php | 94 ------------------- classes/submission/SubmissionSubjectVocab.php | 90 ------------------ .../filter/NativeXmlPKPPublicationFilter.php | 26 ++--- .../filter/PKPPublicationNativeXmlFilter.php | 26 ++--- tests/classes/publication/PublicationTest.php | 4 - .../ValidatorControlledVocabTest.php | 5 + 13 files changed, 150 insertions(+), 456 deletions(-) delete mode 100644 classes/submission/SubmissionAgencyVocab.php delete mode 100644 classes/submission/SubmissionDisciplineVocab.php delete mode 100644 classes/submission/SubmissionKeywordVocab.php delete mode 100644 classes/submission/SubmissionSubjectVocab.php diff --git a/api/v1/vocabs/PKPVocabController.php b/api/v1/vocabs/PKPVocabController.php index 55dda0f32f3..3cb342baec7 100644 --- a/api/v1/vocabs/PKPVocabController.php +++ b/api/v1/vocabs/PKPVocabController.php @@ -23,18 +23,14 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Route; +use PKP\controlledVocab\ControlledVocab; use PKP\core\PKPBaseController; use PKP\core\PKPRequest; -use PKP\db\DAORegistry; use PKP\facades\Locale; use PKP\plugins\Hook; use PKP\security\authorization\ContextAccessPolicy; use PKP\security\authorization\UserRolesRequiredPolicy; use PKP\security\Role; -use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineVocab; -use PKP\submission\SubmissionKeywordVocab; -use PKP\submission\SubmissionSubjectVocab; class PKPVocabController extends PKPBaseController { @@ -113,26 +109,13 @@ public function getMany(Request $illuminateRequest): JsonResponse ], Response::HTTP_BAD_REQUEST); } - switch ($vocab) { - case SubmissionKeywordVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD: - $submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO'); /** @var \PKP\submission\SubmissionKeywordEntryDAO $submissionKeywordEntryDao */ - $entries = $submissionKeywordEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray(); - break; - case SubmissionSubjectVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT: - $submissionSubjectEntryDao = DAORegistry::getDAO('SubmissionSubjectEntryDAO'); /** @var \PKP\submission\SubmissionSubjectEntryDAO $submissionSubjectEntryDao */ - $entries = $submissionSubjectEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray(); - break; - case SubmissionDisciplineVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE: - $submissionDisciplineEntryDao = DAORegistry::getDAO('SubmissionDisciplineEntryDAO'); /** @var \PKP\submission\SubmissionDisciplineEntryDAO $submissionDisciplineEntryDao */ - $entries = $submissionDisciplineEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray(); - break; - 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; - default: - $entries = []; - Hook::call('API::vocabs::getMany', [$vocab, &$entries, $illuminateRequest, response(), $request]); + if (ControlledVocab::hasDefinedVocabSymbolic($vocab)) { + /** @var \PKP\controlledVocab\ControlledVocabEntryDAO $entryDao */ + $entryDao = Repo::controlledVocab()->getEntryDaoBySymbolic($vocab); + $entries = $entryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray(); + } else { + $entries = []; + Hook::call('API::vocabs::getMany', [$vocab, &$entries, $illuminateRequest, response(), $request]); } $data = []; diff --git a/classes/components/forms/publication/Details.php b/classes/components/forms/publication/Details.php index b03b3d7bed8..76229c2c361 100644 --- a/classes/components/forms/publication/Details.php +++ b/classes/components/forms/publication/Details.php @@ -18,7 +18,7 @@ use APP\publication\Publication; use PKP\components\forms\FieldControlledVocab; use PKP\context\Context; -use PKP\submission\SubmissionKeywordVocab; +use PKP\controlledVocab\ControlledVocab; class Details extends TitleAbstractForm { @@ -46,7 +46,7 @@ public function __construct( 'label' => __('common.keywords'), 'description' => __('manager.setup.metadata.keywords.description'), 'isMultilingual' => true, - 'apiUrl' => str_replace('__vocab__', SubmissionKeywordVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase), + 'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase), 'locales' => $this->locales, 'value' => (array) $publication->getData('keywords'), 'isRequired' => $context->getData('keywords') === Context::METADATA_REQUIRE ? true : false, diff --git a/classes/components/forms/publication/PKPMetadataForm.php b/classes/components/forms/publication/PKPMetadataForm.php index c7dd0f8ade9..f36082548be 100644 --- a/classes/components/forms/publication/PKPMetadataForm.php +++ b/classes/components/forms/publication/PKPMetadataForm.php @@ -16,15 +16,12 @@ namespace PKP\components\forms\publication; use APP\publication\Publication; +use PKP\controlledVocab\ControlledVocab; use PKP\components\forms\FieldControlledVocab; use PKP\components\forms\FieldRichTextarea; use PKP\components\forms\FieldText; use PKP\components\forms\FormComponent; use PKP\context\Context; -use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineVocab; -use PKP\submission\SubmissionKeywordVocab; -use PKP\submission\SubmissionSubjectVocab; class PKPMetadataForm extends FormComponent { @@ -55,7 +52,7 @@ public function __construct(string $action, array $locales, Publication $publica 'label' => __('common.keywords'), 'tooltip' => __('manager.setup.metadata.keywords.description'), 'isMultilingual' => true, - 'apiUrl' => str_replace('__vocab__', SubmissionKeywordVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase), + 'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase), 'locales' => $this->locales, 'value' => (array) $publication->getData('keywords'), ])); @@ -66,7 +63,7 @@ public function __construct(string $action, array $locales, Publication $publica 'label' => __('common.subjects'), 'tooltip' => __('manager.setup.metadata.subjects.description'), 'isMultilingual' => true, - 'apiUrl' => str_replace('__vocab__', SubmissionSubjectVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, $suggestionUrlBase), + 'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, $suggestionUrlBase), 'locales' => $this->locales, 'value' => (array) $publication->getData('subjects'), ])); @@ -77,7 +74,7 @@ public function __construct(string $action, array $locales, Publication $publica 'label' => __('search.discipline'), 'tooltip' => __('manager.setup.metadata.disciplines.description'), 'isMultilingual' => true, - 'apiUrl' => str_replace('__vocab__', SubmissionDisciplineVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, $suggestionUrlBase), + 'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, $suggestionUrlBase), 'locales' => $this->locales, 'value' => (array) $publication->getData('disciplines'), ])); @@ -88,7 +85,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__', SubmissionAgencyVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $suggestionUrlBase), + 'apiUrl' => str_replace('__vocab__', ControlledVocab::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 ccdc18105bd..c4bf848ebde 100644 --- a/classes/controlledVocab/ControlledVocab.php +++ b/classes/controlledVocab/ControlledVocab.php @@ -26,6 +26,12 @@ class ControlledVocab extends Model { use HasCamelCasing; + public const CONTROLLED_VOCAB_SUBMISSION_AGENCY = 'submissionAgency'; + public const CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE = 'submissionDiscipline'; + public const CONTROLLED_VOCAB_SUBMISSION_KEYWORD = 'submissionKeyword'; + public const CONTROLLED_VOCAB_SUBMISSION_LANGUAGE = 'submissionLanguage'; + public const CONTROLLED_VOCAB_SUBMISSION_SUBJECT = 'submissionSubject'; + protected $table = 'controlled_vocabs'; protected $primaryKey = 'controlled_vocab_id'; @@ -40,6 +46,22 @@ class ControlledVocab extends Model */ public $timestamps = false; + public static function getDefinedVocabSymbolic(): array + { + return [ + static::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + static::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, + static::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, + static::CONTROLLED_VOCAB_SUBMISSION_LANGUAGE, + static::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, + ]; + } + + public static function hasDefinedVocabSymbolic(string $vocab): bool + { + return in_array($vocab, static::getDefinedVocabSymbolic()); + } + protected function casts(): array { return [ @@ -60,6 +82,17 @@ protected function id(): Attribute ); } + public function getLocaleFieldNames(): array + { + if (!$this->symbolic) { + return []; + } + + return static::hasDefinedVocabSymbolic($this->symbolic) + ? [$this->symbolic] + : []; + } + /** * Compatibility function for including note IDs in grids. * @@ -70,22 +103,12 @@ public function getId(): int return $this->id; } - /** - * Compatibility function for including notes in grids. - * - * @deprecated 3.5. Use $model or $model->$field instead. Can be removed once the DataObject pattern is removed. - */ - public function getData(?string $field): mixed - { - return $field ? $this->$field : $this; - } - /** * Scope a query to only include notes with a specific user ID. */ public function scopeWithSymbolic(Builder $query, string $symbolic): Builder { - return $query->where(DB::raw('LOWER(symbolic)'), strtolower($symbolic)); + return $query->where('symbolic', $symbolic); } /** diff --git a/classes/publication/DAO.php b/classes/publication/DAO.php index dee019ed0d7..6c18d0964c9 100644 --- a/classes/publication/DAO.php +++ b/classes/publication/DAO.php @@ -14,19 +14,17 @@ namespace PKP\publication; use APP\facades\Repo; +use APP\core\Application; use APP\publication\Publication; use Illuminate\Support\Collection; use Illuminate\Support\Enumerable; use Illuminate\Support\Facades\DB; use Illuminate\Support\LazyCollection; use PKP\citation\CitationDAO; +use PKP\controlledVocab\ControlledVocab; use PKP\core\EntityDAO; use PKP\core\traits\EntityWithParent; use PKP\services\PKPSchemaService; -use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineVocab; -use PKP\submission\SubmissionKeywordVocab; -use PKP\submission\SubmissionSubjectVocab; /** * @template T of Publication @@ -348,10 +346,41 @@ protected function deleteAuthors(int $publicationId) */ protected function setControlledVocab(Publication $publication) { - $publication->setData('keywords', SubmissionKeywordVocab::getKeywords($publication->getId())); - $publication->setData('subjects', SubmissionSubjectVocab::getSubjects($publication->getId())); - $publication->setData('disciplines', SubmissionDisciplineVocab::getDisciplines($publication->getId())); - $publication->setData('supportingAgencies', SubmissionAgencyVocab::getAgencies($publication->getId())); + $publication->setData( + 'keywords', + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId() + ) + ); + + $publication->setData( + 'subjects', + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId() + ) + ); + + $publication->setData( + 'disciplines', + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId() + ) + ); + + $publication->setData( + 'supportingAgencies', + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId() + ) + ); } /** @@ -389,10 +418,10 @@ protected function saveControlledVocab(array $values, int $publicationId) // Update controlled vocabularly for which we have props foreach ($values as $prop => $value) { match ($prop) { - 'keywords' => SubmissionKeywordVocab::insertKeywords($value, $publicationId), - 'subjects' => SubmissionSubjectVocab::insertSubjects($value, $publicationId), - 'disciplines' => SubmissionDisciplineVocab::insertDisciplines($value, $publicationId), - 'supportingAgencies' => SubmissionAgencyVocab::insertAgencies($value, $publicationId), + 'keywords' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId), + 'subjects' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId), + 'disciplines' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId), + 'supportingAgencies' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId), }; } } @@ -402,10 +431,33 @@ protected function saveControlledVocab(array $values, int $publicationId) */ protected function deleteControlledVocab(int $publicationId) { - SubmissionKeywordVocab::insertKeywords([], $publicationId); - SubmissionSubjectVocab::insertSubjects([], $publicationId); - SubmissionDisciplineVocab::insertDisciplines([], $publicationId); - SubmissionAgencyVocab::insertAgencies([], $publicationId); + Repo::controlledVocab()->insertBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, + [], + Application::ASSOC_TYPE_PUBLICATION, + $publicationId + ); + + Repo::controlledVocab()->insertBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, + [], + Application::ASSOC_TYPE_PUBLICATION, + $publicationId + ); + + Repo::controlledVocab()->insertBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, + [], + Application::ASSOC_TYPE_PUBLICATION, + $publicationId + ); + + Repo::controlledVocab()->insertBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, + [], + Application::ASSOC_TYPE_PUBLICATION, + $publicationId + ); } /** diff --git a/classes/submission/SubmissionAgencyVocab.php b/classes/submission/SubmissionAgencyVocab.php deleted file mode 100644 index f027b7da65a..00000000000 --- a/classes/submission/SubmissionAgencyVocab.php +++ /dev/null @@ -1,90 +0,0 @@ -getBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_AGENCY, - $assocType, - $publicationId, - $locales - ); - } - - /** - * Get an array of all of the submission's agencies - */ - public function scopeGetAllUniqueAgencies(Builder $query):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 scopeInsertAgencies( - Builder $query, - 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/submission/SubmissionDisciplineVocab.php b/classes/submission/SubmissionDisciplineVocab.php deleted file mode 100644 index 42217ff74f0..00000000000 --- a/classes/submission/SubmissionDisciplineVocab.php +++ /dev/null @@ -1,92 +0,0 @@ -getBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, - $assocType, - $publicationId, - $locales - ); - } - - /** - * Get an array of all of the submission's disciplines - */ - public function scopeGetAllUniqueDisciplines(Builder $query): array - { - return Repo::controlledVocab()->getAllUniqueBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE - ); - } - - /** - * Add an array of disciplines - * - * @param array $disciplines - * @param int $publicationId - * @param bool $deleteFirst - * @param int $assocType DO NOT USE: For <3.1 to 3.x migration pkp/pkp-lib#3572 pkp/pkp-lib#6213 - */ - public function scopeInsertDisciplines( - Builder $query, - array $disciplines, - int $publicationId, - bool $deleteFirst = true, - int $assocType = PKPApplication::ASSOC_TYPE_PUBLICATION): void - { - Repo::controlledVocab()->insertBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, - $disciplines, - $assocType, - $publicationId, - $deleteFirst - ); - } -} diff --git a/classes/submission/SubmissionKeywordVocab.php b/classes/submission/SubmissionKeywordVocab.php deleted file mode 100644 index 6a371e9809e..00000000000 --- a/classes/submission/SubmissionKeywordVocab.php +++ /dev/null @@ -1,94 +0,0 @@ -getBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, - $assocType, - $publicationId, - $locales - ); - } - - /** - * Get an array of all of the submission's keywords - * - * @return array - */ - public function scopeGetAllUniqueKeywords(Builder $query): array - { - return Repo::controlledVocab()->getAllUniqueBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_KEYWORD - ); - } - - /** - * Add an array of keywords - * - * @param array $keywords - * @param int $publicationId - * @param bool $deleteFirst - * @param int $assocType DO NOT USE: For <3.1 to 3.x migration pkp/pkp-lib#3572 pkp/pkp-lib#6213 - */ - public function scopeInsertKeywords( - Builder $query, - array $keywords, - int $publicationId, - bool $deleteFirst = true, - int $assocType = PKPApplication::ASSOC_TYPE_PUBLICATION - ): void - { - Repo::controlledVocab()->insertBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, - $keywords, - $assocType, - $publicationId, - $deleteFirst - ); - } -} diff --git a/classes/submission/SubmissionSubjectVocab.php b/classes/submission/SubmissionSubjectVocab.php deleted file mode 100644 index 63bb8a09469..00000000000 --- a/classes/submission/SubmissionSubjectVocab.php +++ /dev/null @@ -1,90 +0,0 @@ -getBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, - $assocType, - $publicationId, - $locales - ); - } - - /** - * Get an array of all of the submission's Subjects - */ - public function scopeGetAllUniqueSubjects(Builder $query): array - { - return Repo::controlledVocab()->getAllUniqueBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_SUBJECT - ); - } - - /** - * Add an array of subjects - * - * @param array $subjects - * @param int $publicationId - * @param bool $deleteFirst - * @param int $assocType DO NOT USE: For <3.1 to 3.x migration pkp/pkp-lib#3572 pkp/pkp-lib#6213 - */ - public function scopeInsertSubjects( - Builder $query, - array $subjects, - int $publicationId, - bool $deleteFirst = true, - int $assocType = PKPApplication::ASSOC_TYPE_PUBLICATION - ): void - { - Repo::controlledVocab()->insertBySymbolic( - static::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, - $subjects, - $assocType, - $publicationId, - $deleteFirst - ); - } -} diff --git a/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php b/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php index eb7d47f506f..db84fff1e15 100644 --- a/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php +++ b/plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php @@ -20,14 +20,11 @@ use APP\facades\Repo; use APP\publication\Publication; use PKP\citation\CitationDAO; +use PKP\controlledVocab\ControlledVocab; use PKP\db\DAORegistry; use PKP\filter\Filter; use PKP\filter\FilterGroup; use PKP\plugins\PluginRegistry; -use PKP\submission\SubmissionKeywordVocab; -use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineVocab; -use PKP\submission\SubmissionSubjectVocab; class NativeXmlPKPPublicationFilter extends NativeImportFilter { @@ -142,10 +139,9 @@ public function handleChildElement($n, $publication) if (in_array($n->tagName, $setterMappings)) { $publication->setData($n->tagName, $value, $locale); } elseif (isset($controlledVocabulariesMappings[$n->tagName])) { - $controlledVocabulariesModel = $controlledVocabulariesMappings[$n->tagName][0]; - $insertFunction = $controlledVocabulariesMappings[$n->tagName][1]; - + $symbolic = $controlledVocabulariesMappings[$n->tagName][0]; $controlledVocabulary = []; + for ($nc = $n->firstChild; $nc !== null; $nc = $nc->nextSibling) { if ($nc instanceof \DOMElement) { $controlledVocabulary[] = $nc->textContent; @@ -155,7 +151,13 @@ public function handleChildElement($n, $publication) $controlledVocabulariesValues = []; $controlledVocabulariesValues[$locale] = $controlledVocabulary; - $controlledVocabulariesModel::$insertFunction($controlledVocabulariesValues, $publication->getId(), false); + Repo::controlledVocab()->insertBySymbolic( + $symbolic, + $controlledVocabulariesValues, + Application::ASSOC_TYPE_PUBLICATION, + $publication->getId(), + false + ); $publicationNew = Repo::publication()->get($publication->getId()); $publication->setData($n->tagName, $publicationNew->getData($n->tagName)); @@ -319,10 +321,10 @@ public function _getLocalizedPublicationFields() public function _getControlledVocabulariesMappings() { return [ - 'keywords' => [SubmissionKeywordVocab::class, 'insertKeywords'], - 'agencies' => [SubmissionAgencyVocab::class, 'insertAgencies'], - 'disciplines' => [SubmissionDisciplineVocab::class, 'insertDisciplines'], - 'subjects' => [SubmissionSubjectVocab::class, 'insertSubjects'], + 'keywords' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD], + 'agencies' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY], + 'disciplines' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE], + 'subjects' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT], ]; } diff --git a/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php b/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php index c8937b63140..15ce3161529 100644 --- a/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php +++ b/plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php @@ -17,9 +17,11 @@ namespace PKP\plugins\importexport\native\filter; use APP\core\Application; +use APP\facades\Repo; use APP\plugins\importexport\native\NativeImportExportDeployment; use APP\publication\Publication; use Exception; +use PKP\controlledVocab\ControlledVocab; use PKP\citation\CitationDAO; use PKP\db\DAORegistry; use PKP\filter\FilterGroup; @@ -28,10 +30,6 @@ use PKP\submission\PKPSubmission; use PKP\submission\Representation; use PKP\submission\RepresentationDAOInterface; -use PKP\submission\SubmissionKeywordVocab; -use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineVocab; -use PKP\submission\SubmissionSubjectVocab; class PKPPublicationNativeXmlFilter extends NativeExportFilter { @@ -220,10 +218,14 @@ public function addMetadata($doc, $entityNode, $entity) $supportedLocales = $deployment->getContext()->getSupportedFormLocales(); $controlledVocabulariesMapping = $this->_getControlledVocabulariesMappings(); foreach ($controlledVocabulariesMapping as $controlledVocabulariesNodeName => $mappings) { - $vocabModel = $mappings[0]; - $getFunction = $mappings[1]; - $controlledVocabularyNodeName = $mappings[2]; - $controlledVocabulary = $vocabModel::$getFunction($entity->getId(), $supportedLocales); + $symbolic = $mappings[0]; + $controlledVocabularyNodeName = $mappings[1]; + $controlledVocabulary = Repo::controlledVocab()->getBySymbolic( + $symbolic, + Application::ASSOC_TYPE_PUBLICATION, + $entity->getId(), + $supportedLocales + ); $this->addControlledVocabulary($doc, $entityNode, $controlledVocabulariesNodeName, $controlledVocabularyNodeName, $controlledVocabulary); } } @@ -308,10 +310,10 @@ public function addRepresentations($doc, $entityNode, $entity) public function _getControlledVocabulariesMappings() { return [ - 'keywords' => [SubmissionKeywordVocab::class, 'getKeywords', 'keyword'], - 'agencies' => [SubmissionAgencyVocab::class, 'getAgencies', 'agency'], - 'disciplines' => [SubmissionDisciplineVocab::class, 'getDisciplines', 'discipline'], - 'subjects' => [SubmissionSubjectVocab::class, 'getSubjects', 'subject'], + 'keywords' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, 'keyword'], + 'agencies' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, 'agency'], + 'disciplines' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, 'discipline'], + 'subjects' => [ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, 'subject'], ]; } diff --git a/tests/classes/publication/PublicationTest.php b/tests/classes/publication/PublicationTest.php index 31c92cd8bff..7045dedcb60 100644 --- a/tests/classes/publication/PublicationTest.php +++ b/tests/classes/publication/PublicationTest.php @@ -21,10 +21,6 @@ use APP\publication\Publication; use PKP\citation\CitationDAO; use PKP\services\PKPSchemaService; -use PKP\submission\SubmissionAgencyVocab; -use PKP\submission\SubmissionDisciplineVocab; -use PKP\submission\SubmissionKeywordVocab; -use PKP\submission\SubmissionSubjectVocab; use PKP\tests\PKPTestCase; use PHPUnit\Framework\Attributes\CoversClass; diff --git a/tests/classes/validation/ValidatorControlledVocabTest.php b/tests/classes/validation/ValidatorControlledVocabTest.php index 7cef5d0bf30..3d586b99b8d 100644 --- a/tests/classes/validation/ValidatorControlledVocabTest.php +++ b/tests/classes/validation/ValidatorControlledVocabTest.php @@ -49,5 +49,10 @@ public function testValidatorControlledVocab() self::assertTrue($validator->isValid($controlledVocabEntryId1)); self::assertTrue($validator->isValid($controlledVocabEntryId2)); self::assertFalse($validator->isValid(3)); + + // Delete the test entried + $controlledVocabEntryDao->deleteObjectById($controlledVocabEntryId1); + $controlledVocabEntryDao->deleteObjectById($controlledVocabEntryId2); + $testControlledVocab->delete(); } }