Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#7222 Use default landing page url for current publication #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions filter/PreprintCrossrefXmlFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ 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
$publications = array_reverse($publications, true);
// Always include the current publication
$postedContentNode = $this->createPostedContentNode($doc, $pubObject->getCurrentPublication(), $pubObject);
$bodyNode->appendChild($postedContentNode);
// Loop through other publications in case other DOI's exist
$publications = array_reverse($pubObject->getPublishedPublications());
foreach ($publications as $publication) {
if ($publication->getDoi() && $publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
if ($publication->getDoi() && $publication->getDoi() !== $pubObject->getCurrentPublication()->getDoi()) {
$postedContentNode = $this->createPostedContentNode($doc, $publication, $pubObject);
$bodyNode->appendChild($postedContentNode);
}
Expand Down Expand Up @@ -259,9 +262,13 @@ public function createPostedContentNode($doc, $publication, $submission)
$postedContentNode->appendChild($relationsDataNode);
}

// 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but this might break when the code is run as part of an API request (which might be the case with the new changes). The reason is that when specifying a route type (Application::ROUTE_PAGE) that doesn't match the current request, I think it requires a context path to be passed.

It looks like you've already got a $context in this method, so you should be able to replace the null right after ROUTE_PAGE with $context->getPath(). But you might want to test it first.

}
$postedContentNode->appendChild($this->createDOIDataNode($doc, $publication->getDoi(), $url));

return $postedContentNode;
Expand Down