From ab2d018ef515c38c085862d678c9d98637cfa3dc Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Mon, 16 Dec 2024 20:33:06 +0100 Subject: [PATCH 1/3] fix deprecated submission functions --- OAIMetadataFormat_JATS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OAIMetadataFormat_JATS.php b/OAIMetadataFormat_JATS.php index cdd66c0..8f826a1 100644 --- a/OAIMetadataFormat_JATS.php +++ b/OAIMetadataFormat_JATS.php @@ -217,7 +217,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { $uriNode->setAttribute('xlink:href', $request->url(null, 'article', 'view', [$article->getBestId()])); // Set the article URLs: Galleys - foreach ($article->getGalleys() as $galley) { + foreach ($publication->getData('galleys') as $galley) { $uriNode = $this->_addChildInOrder($articleMetaNode, $doc->createElement('self-uri')); $uriNode->setAttribute('xlink:href', $request->url(null, 'article', 'view', [$article->getBestId(), $galley->getId()])); if (!$galley->getData('urlRemote')) $uriNode->setAttribute('content-type', $galley->getFileType()); From 7cf003736194c758e431cfeff7ffb76e6a0d4dce Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Tue, 17 Dec 2024 13:10:44 +0100 Subject: [PATCH 2/3] pkp/pkp-lib#10726 consider all existing submission metadata langauges --- OAIMetadataFormat_JATS.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/OAIMetadataFormat_JATS.php b/OAIMetadataFormat_JATS.php index 8f826a1..06f1eba 100644 --- a/OAIMetadataFormat_JATS.php +++ b/OAIMetadataFormat_JATS.php @@ -262,7 +262,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { $articleTitleHtml = $doc->createDocumentFragment(); $articleTitleHtml->appendXML( $this->mapHtmlTagsForTitle( - $article->getCurrentPublication()->getLocalizedTitle( + $publication->getLocalizedTitle( $article->getData('locale'), 'html' ) @@ -270,7 +270,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { ); $titleNode->appendChild($articleTitleHtml); - if (!empty($subtitle = $article->getCurrentPublication()->getLocalizedSubTitle($article->getData('locale'), 'html'))) { + if (!empty($subtitle = $publication->getLocalizedSubTitle($article->getData('locale'), 'html'))) { $subtitleHtml = $doc->createDocumentFragment(); $subtitleHtml->appendXML($this->mapHtmlTagsForTitle($subtitle)); @@ -280,7 +280,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { $subtitleNode->appendChild($subtitleHtml); } - foreach ($article->getCurrentPublication()->getTitles('html') as $locale => $title) { + foreach ($publication->getTitles('html') as $locale => $title) { if ($locale == $article->getData('locale')) { continue; } @@ -297,7 +297,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { $titleHtml->appendXML($title); $titleNode->appendChild($titleHtml); - if (!empty($subtitle = $article->getCurrentPublication()->getLocalizedSubTitle($locale, 'html'))) { + if (!empty($subtitle = $publication->getLocalizedSubTitle($locale, 'html'))) { $subtitleNode = $transTitleGroupNode->appendChild($doc->createElement('trans-subtitle')); $subtitleHtml = $doc->createDocumentFragment(); $subtitleHtml->appendXML($this->mapHtmlTagsForTitle($subtitle)); @@ -307,11 +307,12 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { // Set the article keywords. $keywordGroupNode = $xpath->query('//article/front/article-meta/kwd-group')->item(0); + /** @var SubmissionKeywordDAO $submissionKeywordDao */ $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); while (($kwdGroupNodes = $articleMetaNode->getElementsByTagName('kwd-group'))->length !== 0) { $articleMetaNode->removeChild($kwdGroupNodes->item(0)); } - foreach ($submissionKeywordDao->getKeywords($publication->getId(), $journal->getSupportedLocales()) as $locale => $keywords) { + foreach ($submissionKeywordDao->getKeywords($publication->getId()) as $locale => $keywords) { if (empty($keywords)) continue; $kwdGroupNode = $this->_addChildInOrder($articleMetaNode, $doc->createElement('kwd-group')); From 8fee5fbcc38f41c7b31e399465e108227d9415c2 Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Thu, 19 Dec 2024 10:28:26 +0100 Subject: [PATCH 3/3] after review: fix deprecated functions --- OAIMetadataFormatPlugin_JATS.php | 8 ++++---- OAIMetadataFormat_JATS.php | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/OAIMetadataFormatPlugin_JATS.php b/OAIMetadataFormatPlugin_JATS.php index 58ac663..5d7752c 100644 --- a/OAIMetadataFormatPlugin_JATS.php +++ b/OAIMetadataFormatPlugin_JATS.php @@ -15,12 +15,12 @@ namespace APP\plugins\oaiMetadataFormats\oaiJats; +use APP\core\Application; +use APP\notification\NotificationManager; use PKP\plugins\OAIMetadataFormatPlugin; -use PKP\core\PKPApplication; use PKP\core\JSONMessage; use PKP\linkAction\request\AjaxModal; use PKP\linkAction\LinkAction; -use APP\notification\NotificationManager; class OAIMetadataFormatPlugin_JATS extends OAIMetadataFormatPlugin { /** @@ -67,7 +67,7 @@ function getCanEnable() { * @return boolean */ function getEnabled() { - $request = PKPApplication::get()->getRequest(); + $request = Application::get()->getRequest(); if (!$request) return false; $context = $request->getContext(); if (!$context) return false; @@ -79,7 +79,7 @@ function getEnabled() { * @param $enabled boolean */ function setEnabled($enabled) { - $request = PKPApplication::get()->getRequest(); + $request = Application::get()->getRequest(); $context = $request->getContext(); $this->updateSetting($context->getId(), 'enabled', $enabled, 'bool'); } diff --git a/OAIMetadataFormat_JATS.php b/OAIMetadataFormat_JATS.php index 06f1eba..549ef20 100644 --- a/OAIMetadataFormat_JATS.php +++ b/OAIMetadataFormat_JATS.php @@ -21,6 +21,8 @@ use PKP\submissionFile\SubmissionFile; use APP\core\Application; use APP\issue\IssueAction; +use DOMDocument; +use DOMXPath; use PKP\plugins\PluginRegistry; use PKP\plugins\Hook; use PKP\userGroup\UserGroup; @@ -74,7 +76,7 @@ protected function _findJats($record) { $candidateFile = array_shift($candidateFiles); $fileService = app()->get('file'); $filepath = $fileService->get($candidateFile->getData('fileId'))->path; - $doc = new DOMDocument; + $doc = new DOMDocument(); $doc->loadXML($fileService->fs->read($filepath)); } @@ -85,6 +87,7 @@ protected function _findJats($record) { * @copydoc OAIMetadataFormat#toXml */ function toXml($record, $format = null) { + /** @var OAIDAO $oaiDao */ $oaiDao = DAORegistry::getDAO('OAIDAO'); $journal = $record->getData('journal'); $article = $record->getData('article'); @@ -147,12 +150,12 @@ protected function _addChildInOrder($parentNode, $childNode) { * Override elements of the JATS XML with aspects of the OJS article's metadata. * @param $doc DOMDocument * @param $journal Journal - * @param $article Article + * @param $article Submission * @param $section Section * @param $issue Issue */ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { - $xpath = new \DOMXPath($doc); + $xpath = new DOMXPath($doc); $articleMetaNode = $xpath->query('//article/front/article-meta')->item(0); $journalMetaNode = $xpath->query('//article/front/journal-meta')->item(0); if (!$journalMetaNode) { @@ -184,16 +187,16 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { $dateNode->setAttribute('publication-format', 'epub'); } - $dateNode->appendChild($doc->createElement('day'))->appendChild($doc->createTextNode(strftime('%d', $datePublished))); - $dateNode->appendChild($doc->createElement('month'))->appendChild($doc->createTextNode(strftime('%m', $datePublished))); - $dateNode->appendChild($doc->createElement('year'))->appendChild($doc->createTextNode(strftime('%Y', $datePublished))); + $dateNode->appendChild($doc->createElement('day'))->appendChild($doc->createTextNode(date('%d', $datePublished))); + $dateNode->appendChild($doc->createElement('month'))->appendChild($doc->createTextNode(date('%m', $datePublished))); + $dateNode->appendChild($doc->createElement('year'))->appendChild($doc->createTextNode(date('%Y', $datePublished))); } // Set the issue publication date. http://erudit-ps-documentation.readthedocs.io/en/latest/tagset/element-pub-date.html $issueYear = null; if ($issue && $issue->getShowYear()) $issueYear = $issue->getYear(); - if (!$issueYear && $issue && $issue->getDatePublished()) $issueYear = strftime('%Y', strtotime($issue->getDatePublished())); - if (!$issueYear && $datePublished) $issueYear = strftime('%Y', $datePublished); + if (!$issueYear && $issue && $issue->getDatePublished()) $issueYear = date('%Y', strtotime($issue->getDatePublished())); + if (!$issueYear && $datePublished) $issueYear = date('%Y', $datePublished); if ($issueYear) { $match = $xpath->query("//article/front/article-meta/pub-date[@date-type='collection']"); if ($match->length) { @@ -334,7 +337,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { foreach ((array) $publication->getData('abstract') as $locale => $abstract) { if (empty($abstract)) continue; $isPrimary = $locale == $article->getData('locale'); - $abstractDoc = new \DOMDocument; + $abstractDoc = new DOMDocument(); if (strpos($abstract, '

')===null) $abstract = "

$abstract

"; $abstractDoc->loadXML(($isPrimary?'':'') . $purifier->purify($abstract) . ($isPrimary?'':'')); $abstractNode = $this->_addChildInOrder($articleMetaNode, $doc->importNode($abstractDoc->documentElement, true)); @@ -364,7 +367,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { } // Store the DOI - if ($doi = trim($article->getStoredPubId('doi'))) { + if ($doi = trim($publication->getStoredPubId('doi'))) { $match = $xpath->query("//article/front/article-meta/article-id[@pub-id-type='doi']"); if ($match->length) { $originalDoiNode = $match->item(0)->firstChild;