Skip to content

Commit

Permalink
pkp/pkp-lib#7222 Use default landing page url for current publication
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnyga committed Feb 26, 2022
1 parent 61f063b commit 98b39ec
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions filter/PreprintCrossrefXmlFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,30 @@ public function &process(&$pubObjects)
$bodyNode = $doc->createElementNS($deployment->getNamespace(), 'body');
$rootNode->appendChild($bodyNode);

// Loop through all submissions
foreach ($pubObjects as $pubObject) {
$publications = $pubObject->getData('publications')->toArray();
// Use array reverse so that the latest version of the submission is first in the xml output and the DOI relations do not cause an error with Crossref

// Get all published publications for this submission
$publications = $pubObject->getPublishedPublications();

// If first version has the same DOI as the current version, only create a node for the current version and break loop
foreach ($publications as $publication) {
if ($pubObject->getCurrentPublication()->getDoi() && $pubObject->getLatestPublication()->getDoi() === $publication->getDoi()) {
$postedContentNode = $this->createPostedContentNode($doc, $pubObject->getCurrentPublication(), $pubObject);
$bodyNode->appendChild($postedContentNode);
continue 2;
}
}

// If versions have a different DOI, create node for all publications
// Use array reverse so that the current version of the submission is first in the xml output and the DOI relations do not cause an error with Crossref
$publications = array_reverse($publications, true);
foreach ($publications as $publication) {
if ($publication->getDoi() && $publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
if ($publication->getDoi()) {
// If all versions have a different DOI, create node for all publications
$postedContentNode = $this->createPostedContentNode($doc, $publication, $pubObject);
$bodyNode->appendChild($postedContentNode);

}
}
}
Expand Down Expand Up @@ -243,14 +259,18 @@ public function createPostedContentNode($doc, $publication, $submission)
$postedContentNode->appendChild($licenseNode);
}

// DOI relations
if ($submission->getLatestPublication()->getDoi() && $submission->getLatestPublication()->getDoi() != $publication->getDoi()) {
$postedContentNode->appendChild($this->createRelationsDataNode($doc, $submission->getLatestPublication()->getDoi()));
// DOI relations: if this version has a different DOI than the current publication (ie. versions and DOI versioning exits), add a relation node
if ($submission->getCurrentPublication()->getDoi() && $submission->getCurrentPublication()->getDoi() != $publication->getDoi()) {
$postedContentNode->appendChild($this->createRelationsDataNode($doc, $submission->getCurrentPublication()->getDoi()));
}

// DOI data
// DOI data: for the current publication use default landing page URL, for other versions use a version specific URL, see https://github.com/pkp/pkp-lib/issues/7222
$dispatcher = $this->_getDispatcher($request);
$url = $dispatcher->url($request, Application::ROUTE_PAGE, null, 'preprint', 'view', [$submission->getBestId(), 'version', $publication->getId()], null, null, true);
if ($submission->getCurrentPublication()->getId() === $publication->getId()) {
$url = $dispatcher->url($request, Application::ROUTE_PAGE, null, 'preprint', 'view', $submission->getBestId());
} else {
$url = $dispatcher->url($request, Application::ROUTE_PAGE, null, 'preprint', 'view', [$submission->getBestId(), 'version', $publication->getId()], null, null, true);
}
$postedContentNode->appendChild($this->createDOIDataNode($doc, $publication->getDoi(), $url));

return $postedContentNode;
Expand Down

0 comments on commit 98b39ec

Please sign in to comment.