Skip to content

Commit

Permalink
Merge pull request #62 from bozana/10653
Browse files Browse the repository at this point in the history
fix deprecated submission functions
  • Loading branch information
bozana authored Dec 19, 2024
2 parents 51bf1b3 + 8fee5fb commit c6d8f1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
8 changes: 4 additions & 4 deletions OAIMetadataFormatPlugin_JATS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
Expand All @@ -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');
}
Expand Down
36 changes: 20 additions & 16 deletions OAIMetadataFormat_JATS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -217,7 +220,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());
Expand Down Expand Up @@ -262,15 +265,15 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) {
$articleTitleHtml = $doc->createDocumentFragment();
$articleTitleHtml->appendXML(
$this->mapHtmlTagsForTitle(
$article->getCurrentPublication()->getLocalizedTitle(
$publication->getLocalizedTitle(
$article->getData('locale'),
'html'
)
)
);
$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));
Expand All @@ -280,7 +283,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;
}
Expand All @@ -297,7 +300,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));
Expand All @@ -307,11 +310,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'));
Expand All @@ -333,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, '<p>')===null) $abstract = "<p>$abstract</p>";
$abstractDoc->loadXML(($isPrimary?'<abstract>':'<trans-abstract>') . $purifier->purify($abstract) . ($isPrimary?'</abstract>':'</trans-abstract>'));
$abstractNode = $this->_addChildInOrder($articleMetaNode, $doc->importNode($abstractDoc->documentElement, true));
Expand Down Expand Up @@ -363,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;
Expand Down

0 comments on commit c6d8f1c

Please sign in to comment.