From ff29d0575484d6f56fa962235a066e4d69bb8bf2 Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Wed, 17 Jun 2026 15:56:02 +0200 Subject: [PATCH] pkp/pkp-lib#7527 Stamp press identity metadata onto publications --- api/v1/submissions/SubmissionController.php | 2 +- .../forms/publication/CatalogEntryForm.php | 42 ++- .../upgrade/v3_6_0/I7527_IdentityMetadata.php | 41 +++ .../HasContextIdentityMetadata.php | 47 +++ classes/publication/Publication.php | 24 ++ dbscripts/xml/upgrade.xml | 1 + locale/en/manager.po | 3 + locale/en/submission.po | 6 + pages/workflow/WorkflowHandler.php | 2 +- .../googleScholar/GoogleScholarPlugin.php | 2 +- .../filter/NativeXmlPublicationFilter.php | 3 + .../filter/PublicationNativeXmlFilter.php | 10 + plugins/importexport/native/native.xsd | 4 + .../filter/MonographONIX30XmlFilter.php | 8 +- .../Dc11SchemaPublicationFormatAdapter.php | 6 +- schemas/publication.json | 35 ++- tools/stampIdentityMetadata.php | 279 ++++++++++++++++++ 17 files changed, 494 insertions(+), 21 deletions(-) create mode 100644 classes/migration/upgrade/v3_6_0/I7527_IdentityMetadata.php create mode 100644 classes/publication/HasContextIdentityMetadata.php create mode 100644 tools/stampIdentityMetadata.php diff --git a/api/v1/submissions/SubmissionController.php b/api/v1/submissions/SubmissionController.php index 9df3223f800..b349015d807 100644 --- a/api/v1/submissions/SubmissionController.php +++ b/api/v1/submissions/SubmissionController.php @@ -105,7 +105,7 @@ protected function getCatalogEntryForm(Request $illuminateRequest): JsonResponse $publicFileManager = new PublicFileManager(); $baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId()); - $catalogEntryForm = new CatalogEntryForm($publicationApiUrl, $locales, $publication, $submission, $baseUrl, $temporaryFileApiUrl); + $catalogEntryForm = new CatalogEntryForm($publicationApiUrl, $locales, $publication, $submission, $baseUrl, $temporaryFileApiUrl, $context); $submissionLocale = $submission->getData('locale'); return response()->json($this->getLocalizedForm($catalogEntryForm, $submissionLocale, $locales), Response::HTTP_OK); diff --git a/classes/components/forms/publication/CatalogEntryForm.php b/classes/components/forms/publication/CatalogEntryForm.php index c785a22a700..f3a526bd395 100644 --- a/classes/components/forms/publication/CatalogEntryForm.php +++ b/classes/components/forms/publication/CatalogEntryForm.php @@ -18,9 +18,11 @@ namespace APP\components\forms\publication; use APP\facades\Repo; +use APP\press\Press; use APP\publication\Publication; use APP\submission\Submission; use PKP\components\forms\FieldAutosuggestPreset; +use PKP\components\forms\FieldHTML; use PKP\components\forms\FieldRichTextarea; use PKP\components\forms\FieldSelect; use PKP\components\forms\FieldText; @@ -37,6 +39,7 @@ class CatalogEntryForm extends FormComponent public const GROUP_VERSION_AND_UPDATES = 'versionAndUpdates'; public const GROUP_DISPLAY = 'display'; public const GROUP_ACCESS = 'access'; + public const GROUP_PRESS_IDENTITY = 'pressIdentity'; public $id = self::FORM_CATALOG_ENTRY; public $method = 'PUT'; @@ -53,8 +56,9 @@ class CatalogEntryForm extends FormComponent * @param Submission $submission The submission of this publication * @param string $baseUrl Site's base URL. Used for image previews. * @param string $temporaryFileApiUrl The url to upload the cover image + * @param Press $press The press this publication belongs to */ - public function __construct($action, $locales, $publication, $submission, $baseUrl, $temporaryFileApiUrl) + public function __construct($action, $locales, $publication, $submission, $baseUrl, $temporaryFileApiUrl, ?Press $press = null) { $this->action = $action; $this->successMessage = __('publication.catalogEntry.success'); @@ -172,5 +176,41 @@ public function __construct($action, $locales, $publication, $submission, $baseU 'description' => __('publication.urlPath.description'), 'value' => $publication->getData('urlPath'), ])); + + if ($press) { + $this->addStampedIdentityField($publication, $press); + } + } + + protected function addStampedIdentityField(Publication $publication, Press $press): void + { + $parts = []; + + if ($publication->getData('contextName')) { + $parts[] = '
  • ' . htmlspecialchars(__('manager.setup.contextTitle')) . ': ' + . htmlspecialchars($publication->getPrimaryContextName($press)) . '
  • '; + } + if ($publisher = $publication->getData('publisher')) { + $parts[] = '
  • ' . htmlspecialchars(__('manager.setup.publisher')) . ': ' + . htmlspecialchars($publisher) . '
  • '; + } + if ($publisherLocation = $publication->getData('publisherLocation')) { + $parts[] = '
  • ' . htmlspecialchars(__('manager.setup.publisherLocation')) . ': ' + . htmlspecialchars($publisherLocation) . '
  • '; + } + + if (empty($parts)) { + return; + } + + $this->addGroup( + ['id' => self::GROUP_PRESS_IDENTITY, 'label' => __('publication.pressIdentity')] + ); + $this->addField(new FieldHTML('pressIdentity', [ + 'groupId' => self::GROUP_PRESS_IDENTITY, + 'label' => __('publication.pressIdentity'), + 'description' => __('publication.pressIdentity.description') + . '', + ])); } } diff --git a/classes/migration/upgrade/v3_6_0/I7527_IdentityMetadata.php b/classes/migration/upgrade/v3_6_0/I7527_IdentityMetadata.php new file mode 100644 index 00000000000..5aadd08c009 --- /dev/null +++ b/classes/migration/upgrade/v3_6_0/I7527_IdentityMetadata.php @@ -0,0 +1,41 @@ + 'publisherLocation']; + $rows = DB::table($settingsTable) + ->where($idColumn, $contextId) + ->whereIn('setting_name', ['publisher', 'codeType', 'codeValue', 'location']) + ->where('setting_value', '!=', '') + ->pluck('setting_value', 'setting_name'); + + foreach ($rows as $name => $value) { + $settings[$rename[$name] ?? $name] = $value; + } + + return $settings; + } +} diff --git a/classes/publication/HasContextIdentityMetadata.php b/classes/publication/HasContextIdentityMetadata.php new file mode 100644 index 00000000000..65c8b10a9be --- /dev/null +++ b/classes/publication/HasContextIdentityMetadata.php @@ -0,0 +1,47 @@ +getData('publisher') ?: $context->getData('publisher'); + } + + /** + * Get the stamped publisher code type, falling back to the live context value. + */ + public function getCodeType(Context $context): ?string + { + return $this->getData('codeType') ?: $context->getData('codeType'); + } + + /** + * Get the stamped publisher code value, falling back to the live context value. + */ + public function getCodeValue(Context $context): ?string + { + return $this->getData('codeValue') ?: $context->getData('codeValue'); + } +} diff --git a/classes/publication/Publication.php b/classes/publication/Publication.php index 00f503d040e..3fe28c5500d 100644 --- a/classes/publication/Publication.php +++ b/classes/publication/Publication.php @@ -22,10 +22,13 @@ use APP\facades\Repo; use APP\file\PublicFileManager; use APP\publication\enums\VersionStage; +use PKP\context\Context; use PKP\publication\PKPPublication; class Publication extends PKPPublication { + use HasContextIdentityMetadata; + public const DEFAULT_VERSION_STAGE = VersionStage::VERSION_OF_RECORD; /** @@ -111,4 +114,25 @@ public function getLocalizedCoverImageThumbnailUrl(int $contextId) Repo::publication()->getThumbnailFilename($pathParts['basename']), ]); } + + /** + * Stamp press identity onto the publication. + */ + public function stampContextIdentity(?Context $context = null): void + { + $context ??= $this->getStampingContext(); + parent::stampContextIdentity($context); + $this->setData('publisher', $context->getData('publisher')); + $this->setData('publisherLocation', $context->getData('location')); + $this->setData('codeType', $context->getData('codeType')); + $this->setData('codeValue', $context->getData('codeValue')); + } + + public function clearIdentityMetadata(): void + { + parent::clearIdentityMetadata(); + $this->setData('publisher', null); + $this->setData('codeType', null); + $this->setData('codeValue', null); + } } diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index 978d9540178..b8f14ebab53 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -211,6 +211,7 @@ +