Skip to content

Commit

Permalink
after review: fix deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Dec 19, 2024
1 parent b7cbed9 commit 732a26b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getTemplateVarsFromRowColumn($row, $column)

switch ($columnId) {
case 'pubId':
return ['label' => $submission->getStoredPubId($this->_plugin->getPubIdType())];
return ['label' => $submission->getCurrentPublication()->getStoredPubId($this->_plugin->getPubIdType())];
}
return parent::getTemplateVarsFromRowColumn($row, $column);
}
Expand Down
148 changes: 27 additions & 121 deletions plugins/generic/datacite/filter/DataciteXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use APP\plugins\generic\datacite\DataciteExportPlugin;
use APP\publication\Publication;
use APP\submission\Submission;
use DOMDocument;
use DOMNode;
use PKP\context\Context;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
Expand Down Expand Up @@ -87,9 +90,8 @@ public function __construct($filterGroup)
*
* @param Issue|Submission|Galley $pubObject
*
* @return \DOMDocument
*/
public function &process(&$pubObject)
public function &process(&$pubObject): DOMDocument
{
// Create the XML document
$doc = new \DOMDocument('1.0', 'utf-8');
Expand All @@ -103,20 +105,22 @@ public function &process(&$pubObject)
$cache = $plugin->getCache();

// Get all objects
$issue = $article = $galley = $galleyFile = null;
$issue = $article = $galley = $galleyFile = $doi = null;
if ($pubObject instanceof Issue) {
$issue = $pubObject;
if (!$cache->isCached('issues', $issue->getId())) {
$cache->add($issue, null);
}
$doi = $issue->getDoi();
} elseif ($pubObject instanceof Submission) {
$article = $pubObject;
if (!$cache->isCached('articles', $article->getId())) {
$cache->add($article, null);
}
$doi = $article->getCurrentPublication()->getDoi();
} elseif ($pubObject instanceof Galley) {
$galley = $pubObject;
$galleyFile = $galley->getFile();
$galleyFile = Repo::submissionFile()->get($galley->getData('submissionFileId'));
$publication = Repo::publication()->get($galley->getData('publicationId'));
if ($cache->isCached('articles', $publication->getData('submissionId'))) {
$article = $cache->get('articles', $publication->getData('submissionId'));
Expand All @@ -138,6 +142,7 @@ public function &process(&$pubObject)
}
}
}
$doi = $galley->getDoi();
}
if (!$issue) {
$issueId = $article->getCurrentPublication()->getData('issueId');
Expand Down Expand Up @@ -174,7 +179,6 @@ public function &process(&$pubObject)
$rootNode = $this->createRootNode($doc);
$doc->appendChild($rootNode);
// DOI (mandatory)
$doi = $pubObject->getStoredPubId('doi');
if ($plugin->isTestMode($context)) {
$testDOIPrefix = $plugin->getSetting($context->getId(), 'testDOIPrefix');
assert(!empty($testDOIPrefix));
Expand Down Expand Up @@ -264,12 +268,8 @@ public function &process(&$pubObject)
//
/**
* Create and return the root node.
*
* @param \DOMDocument $doc
*
* @return \DOMElement
*/
public function createRootNode($doc)
public function createRootNode(DOMDocument $doc): DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand All @@ -281,18 +281,8 @@ public function createRootNode($doc)

/**
* Create creators node.
*
* @param \DOMDocument $doc
* @param \APP\issue\Issue $issue
* @param \APP\publication\Publication $publication
* @param \PKP\galley\Galley $galley
* @param \PKP\submissionFile\SubmissionFile $galleyFile
* @param string $publisher
* @param array $objectLocalePrecedence
*
* @return \DOMElement
*/
public function createCreatorsNode($doc, $issue, $publication, $galley, $galleyFile, $publisher, $objectLocalePrecedence)
public function createCreatorsNode(DOMDocument $doc, Issue $issue, Publication $publication, Galley $galley, SubmissionFile $galleyFile, string $publisher, array $objectLocalePrecedence): DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -366,17 +356,8 @@ public function createCreatorsNode($doc, $issue, $publication, $galley, $galleyF

/**
* Create titles node.
*
* @param \DOMDocument $doc
* @param \APP\issue\Issue $issue
* @param \APP\publication\Publication $publication
* @param \PKP\galley\Galley $galley
* @param \PKP\submissionFile\SubmissionFile $galleyFile
* @param array $objectLocalePrecedence
*
* @return \DOMElement
*/
public function createTitlesNode($doc, $issue, $publication, $galley, $galleyFile, $objectLocalePrecedence)
public function createTitlesNode(DOMDocument $doc, Issue $issue, Publication $publication, Galley $galley, SubmissionFile $galleyFile, array $objectLocalePrecedence): DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -419,18 +400,8 @@ public function createTitlesNode($doc, $issue, $publication, $galley, $galleyFil

/**
* Create a date node list.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Publication $publication
* @param Galley $galley
* @param SubmissionFile $galleyFile
* @param string $publicationDate
*
* @return \DOMElement
*/
public function createDatesNode($doc, $issue, $article, $publication, $galley, $galleyFile, $publicationDate)
public function createDatesNode(DOMDocument $doc, Issue $issue, Submission $article, Publication $publication, Galley $galley, SubmissionFile $galleyFile, string $publicationDate): DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -508,16 +479,8 @@ public function createDatesNode($doc, $issue, $article, $publication, $galley, $

/**
* Create a resource type node.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Galley $galley
* @param SubmissionFile $galleyFile
*
* @return \DOMElement
*/
public function createResourceTypeNode($doc, $issue, $article, $galley, $galleyFile)
public function createResourceTypeNode(DOMDocument $doc, Issue $issue, Submission $article, Galley $galley, SubmissionFile $galleyFile): DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -561,15 +524,8 @@ public function createResourceTypeNode($doc, $issue, $article, $galley, $galleyF

/**
* Generate alternate identifiers node list.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Galley $galley
*
* @return \DOMElement
*/
public function createAlternateIdentifiersNode($doc, $issue, $article, $galley)
public function createAlternateIdentifiersNode(DOMDocument $doc, Issue $issue, Submission $article, Galley $galley): DOMNode
{
$deployment = $this->getDeployment();
$context = $deployment->getContext();
Expand Down Expand Up @@ -605,24 +561,16 @@ public function createAlternateIdentifiersNode($doc, $issue, $article, $galley)

/**
* Generate related identifiers node list.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Publication $publication
* @param Galley $galley
*
* @return ?\DOMElement
*/
public function createRelatedIdentifiersNode($doc, $issue, $article, $publication, $galley)
public function createRelatedIdentifiersNode(DOMDocument $doc, Issue $issue, Submission $article, Publication $publication, Galley $galley): ?DOMNode
{
$deployment = $this->getDeployment();
$relatedIdentifiersNode = $doc->createElementNS($deployment->getNamespace(), 'relatedIdentifiers');
switch (true) {
case isset($galley):
// Part of: article.
assert(isset($article));
$doi = $article->getStoredPubId('doi');
$doi = $publication->getStoredPubId('doi');
if (!empty($doi)) {
$relatedIdentifiersNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'relatedIdentifier', htmlspecialchars($doi, ENT_COMPAT, 'UTF-8')));
$node->setAttribute('relatedIdentifierType', DATACITE_IDTYPE_DOI);
Expand Down Expand Up @@ -679,17 +627,8 @@ public function createRelatedIdentifiersNode($doc, $issue, $article, $publicatio

/**
* Create a sizes node list.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Publication $publication
* @param Galley $galley
* @param SubmissionFile $galleyFile
*
* @return ?\DOMElement Can be null if a size cannot be identified for the given object.
*/
public function createSizesNode($doc, $issue, $article, $publication, $galley, $galleyFile)
public function createSizesNode(DOMDocument $doc, Issue $issue, Submission $article, Publication $publication, Galley $galley, SubmissionFile $galleyFile): ?DOMNode
{
$deployment = $this->getDeployment();
$sizes = [];
Expand Down Expand Up @@ -726,18 +665,8 @@ public function createSizesNode($doc, $issue, $article, $publication, $galley, $

/**
* Create descriptions node list.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Publication $publication
* @param Galley $galley
* @param SubmissionFile $galleyFile
* @param array $objectLocalePrecedence
*
* @return ?\DOMElement Can be null if a size cannot be identified for the given object.
*/
public function createDescriptionsNode($doc, $issue, $article, $publication, $galley, $galleyFile, $objectLocalePrecedence)
public function createDescriptionsNode(DOMDocument $doc, Issue $issue, Submission $article, Publication $publication, Galley $galley, SubmissionFile $galleyFile, array $objectLocalePrecedence): ?DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -785,17 +714,8 @@ public function createDescriptionsNode($doc, $issue, $article, $publication, $ga

/**
* Create related items node.
*
* @param \DOMDocument $doc
* @param Issue $issue
* @param Submission $article
* @param Publication $publication
* @param string $publisher
* @param array $objectLocalePrecedence
*
* @return ?\DOMElement Can be null if a size cannot be identified for the given object.
*/
public function createRelatedItemsNode($doc, $issue, $article, $publication, $publisher, $objectLocalePrecedence)
public function createRelatedItemsNode(DOMDocument $doc, Issue $issue, Submission $article, Publication $publication, string $publisher, array $objectLocalePrecedence): ?DOMNode
{
/** @var DataciteExportDeployment */
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -878,15 +798,9 @@ public function createRelatedItemsNode($doc, $issue, $article, $publication, $pu
/**
* Identify the locale precedence for this export.
*
* @param \PKP\context\Context $context
* @param \APP\submission\Submission $article
* @param \APP\publication\Publication $publication
* @param \PKP\galley\Galley $galley
*
* @return array A list of valid PKP locales in descending
* order of priority.
* @return array A list of valid PKP locales ordered by priority.
*/
public function getObjectLocalePrecedence($context, $article, $publication, $galley)
public function getObjectLocalePrecedence(Context $context, Submission $article, Publication $publication, Galley $galley): array
{
$locales = [];
if ($galley instanceof Galley && Locale::isLocaleValid($galley->getLocale())) {
Expand Down Expand Up @@ -947,10 +861,10 @@ public function translateLanguageToLocale($language)
* @param array $localePrecedence An array of locales
* by descending priority.
*
* @return mixed|null The value of the primary locale
* @return mixed The value of the primary locale
* or null if no primary translation could be found.
*/
public function getPrimaryTranslation($localizedData, $localePrecedence)
public function getPrimaryTranslation(array $localizedData, array $localePrecedence): mixed
{
// Check whether we have localized data at all.
if (!is_array($localizedData) || empty($localizedData)) {
Expand Down Expand Up @@ -984,7 +898,7 @@ public function getPrimaryTranslation($localizedData, $localePrecedence)
*
* @return array Re-ordered localized data.
*/
public function getTranslationsByPrecedence($localizedData, $localePrecedence)
public function getTranslationsByPrecedence(array $localizedData, array $localePrecedence): array
{
$reorderedLocalizedData = [];

Expand Down Expand Up @@ -1013,13 +927,10 @@ public function getTranslationsByPrecedence($localizedData, $localePrecedence)
* Construct an issue title from the journal title
* and the issue identification.
*
* @param \APP\issue\Issue $issue
* @param array $objectLocalePrecedence
*
* @return array|string An array of localized issue titles
* or a string if a locale has been given.
*/
public function getIssueInformation($issue, $objectLocalePrecedence = null)
public function getIssueInformation(Issue $issue, array $objectLocalePrecedence = null): array|string
{
$deployment = $this->getDeployment();
$context = $deployment->getContext();
Expand All @@ -1042,13 +953,8 @@ public function getIssueInformation($issue, $objectLocalePrecedence = null)

/**
* Construct a table of content for an issue.
*
* @param \APP\issue\Issue $issue
* @param array $objectLocalePrecedence
*
* @return string
*/
public function getIssueToc($issue, $objectLocalePrecedence)
public function getIssueToc(Issue $issue, array $objectLocalePrecedence): string
{
$submissions = Repo::submission()
->getCollector()
Expand Down
2 changes: 1 addition & 1 deletion plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function &extractMetadataFromDataObject(&$article)
if ($issue && $pubIssueId = $issue->getStoredPubId($publicIdentifier)) {
$dc11Description->addStatement('dc:source', $pubIssueId, MetadataDescription::METADATA_DESCRIPTION_UNKNOWN_LOCALE);
}
if ($pubArticleId = $article->getStoredPubId($publicIdentifier)) {
if ($pubArticleId = $publication->getStoredPubId($publicIdentifier)) {
$dc11Description->addStatement('dc:identifier', $pubArticleId);
}
foreach ($galleys as $galley) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/reports/articles/ArticleReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ public function display($args, $request)
'agencies' => join(', ', $agencies[Locale::getLocale()] ?? $agencies[$submission->getData('locale')] ?? []),
'status' => $submission->getData('status') == PKPSubmission::STATUS_QUEUED ? $this->getStageLabel($submission->getData('stageId')) : __($statusMap[$submission->getData('status')]),
'url' => $request->url(null, 'workflow', 'access', $submission->getId()),
'doi' => $submission->getStoredPubId('doi'),
'doi' => $publication->getDoi(),
'dateSubmitted' => $submission->getData('dateSubmitted'),
'lastModified' => $submission->getLastModified(),
'lastModified' => $submission->getData('lastModified'),
'firstPublished' => $submission->getOriginalPublication()?->getData('datePublished') ?? '',
'editors' => $editors,
'decisions' => $editDecisions->toArray(),
Expand Down
2 changes: 1 addition & 1 deletion templates/frontend/objects/article_details.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
{if $pubIdPlugin->getPubIdType() == 'doi'}
{continue}
{/if}
{assign var=pubId value=$article->getStoredPubId($pubIdPlugin->getPubIdType())}
{assign var=pubId value=$publication->getStoredPubId($pubIdPlugin->getPubIdType())}
{if $pubId}
<section class="item pubid">
<h2 class="label">
Expand Down

0 comments on commit 732a26b

Please sign in to comment.