diff --git a/CrossrefPlugin.php b/CrossrefPlugin.php index 2cbb67e..b6aee5a 100644 --- a/CrossrefPlugin.php +++ b/CrossrefPlugin.php @@ -488,9 +488,9 @@ function ($attribute, $value, $fail) use ($context, $publication) { ]; $metadata = [ - 'publisherInstitution' => $context->getData('publisherInstitution'), - 'onlineIssn' => $context->getData('onlineIssn'), - 'printIssn' => $context->getData('printIssn'), + 'publisherInstitution' => $publication->getPublisher($context), + 'onlineIssn' => $publication->getOnlineIssn($context), + 'printIssn' => $publication->getPrintIssn($context), 'doi' => $publication->getDoi(), 'issueId' => $issueId, ]; diff --git a/filter/ArticleCrossrefXmlFilter.php b/filter/ArticleCrossrefXmlFilter.php index d099a0a..0979b5e 100644 --- a/filter/ArticleCrossrefXmlFilter.php +++ b/filter/ArticleCrossrefXmlFilter.php @@ -113,7 +113,7 @@ public function createSubmissionJournalNode(DOMDocument $doc, Submission $pubObj $deployment = $this->getDeployment(); $journalNode = $doc->createElementNS($deployment->getNamespace(), 'journal'); - $journalNode->appendChild($this->createJournalMetadataNode($doc)); + $journalNode->appendChild($this->createJournalMetadataNode($doc, $publication)); $issueNode = $this->createSubmissionJournalIssueNode($doc, $publication); if ($issueNode) { $journalNode->appendChild($issueNode); diff --git a/filter/IssueCrossrefXmlFilter.php b/filter/IssueCrossrefXmlFilter.php index 4c81665..7154357 100644 --- a/filter/IssueCrossrefXmlFilter.php +++ b/filter/IssueCrossrefXmlFilter.php @@ -18,6 +18,7 @@ use APP\core\Request; use APP\issue\Issue; use APP\plugins\generic\crossref\CrossrefExportDeployment; +use APP\publication\Publication; use DOMDocument; use DOMElement; use PKP\core\Dispatcher; @@ -129,7 +130,7 @@ public function createJournalNode(DOMDocument $doc, Issue $pubObject): DOMElemen { $deployment = $this->getDeployment(); $journalNode = $doc->createElementNS($deployment->getNamespace(), 'journal'); - $journalNode->appendChild($this->createJournalMetadataNode($doc)); + $journalNode->appendChild($this->createJournalMetadataNode($doc, $pubObject)); $journalNode->appendChild($this->createJournalIssueNode($doc, $pubObject)); return $journalNode; } @@ -137,14 +138,14 @@ public function createJournalNode(DOMDocument $doc, Issue $pubObject): DOMElemen /** * Create and return the journal metadata node 'journal_metadata'. */ - public function createJournalMetadataNode(DOMDocument $doc): DOMElement + public function createJournalMetadataNode(DOMDocument $doc, Issue|Publication $identitySource): DOMElement { $deployment = $this->getDeployment(); $context = $deployment->getContext(); $journalMetadataNode = $doc->createElementNS($deployment->getNamespace(), 'journal_metadata'); // Full title - $journalTitle = $context->getName($context->getPrimaryLocale()); + $journalTitle = $identitySource->getPrimaryContextName($context); // Fall back to the journal abbreviation if the full title is not set in the primary locale. if ($journalTitle == '') { $journalTitle = $context->getData('abbreviation', $context->getPrimaryLocale()); @@ -157,11 +158,11 @@ public function createJournalMetadataNode(DOMDocument $doc): DOMElement } $journalMetadataNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'abbrev_title', htmlspecialchars($journalAbbrev, ENT_COMPAT, 'UTF-8'))); // Both online and print ISSNs are permitted by Crossref — send whichever are available. - if ($ISSN = $context->getData('onlineIssn')) { + if ($ISSN = $identitySource->getOnlineIssn($context)) { $journalMetadataNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'issn', $ISSN)); $node->setAttribute('media_type', 'electronic'); } - if ($ISSN = $context->getData('printIssn')) { + if ($ISSN = $identitySource->getPrintIssn($context)) { $journalMetadataNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'issn', $ISSN)); $node->setAttribute('media_type', 'print'); } diff --git a/tests/JournalMetadataNodeTest.php b/tests/JournalMetadataNodeTest.php new file mode 100644 index 0000000..88d0630 --- /dev/null +++ b/tests/JournalMetadataNodeTest.php @@ -0,0 +1,96 @@ +shouldReceive('getPrimaryLocale')->andReturn('en'); + Registry::set('site', $mockSite); + $this->mockRequest(); + + $this->publication = (new DAO(new PKPSchemaService()))->newDataObject(); + + $this->filter = $this->getMockBuilder(IssueCrossrefXmlFilter::class) + ->disableOriginalConstructor() + ->onlyMethods([]) + ->getMock(); + } + + private function setupDeployment(Journal $journal): void + { + $deployment = Mockery::mock(CrossrefExportDeployment::class); + $deployment->shouldReceive('getContext')->andReturn($journal); + $deployment->shouldReceive('getNamespace')->andReturn(CrossrefExportDeployment::CROSSREF_XMLNS); + $this->filter->setDeployment($deployment); + } + + public function testJournalMetadataUsesStampedIdentityAfterJournalChange(): void + { + $journal = new Journal(); + $journal->setName('Old Journal Name', 'en'); + $journal->setPrimaryLocale('en'); + $journal->setData('onlineIssn', 'old-online-issn'); + $journal->setData('printIssn', 'old-print-issn'); + $journal->setData('publisherInstitution', 'Old Publisher'); + $journal->setData('abbreviation', 'J.Old', 'en'); + + $this->publication->stampContextIdentity($journal); + + // Journal is later renamed and its ISSNs changed — the stamp must remain authoritative. + $journal->setName('New Journal Name', 'en'); + $journal->setData('onlineIssn', 'new-online-issn'); + $journal->setData('printIssn', 'new-print-issn'); + + $this->setupDeployment($journal); + $xml = $this->filter->createJournalMetadataNode(new DOMDocument(), $this->publication); + $xmlString = $xml->ownerDocument->saveXML($xml); + + $this->assertStringContainsString('Old Journal Name', $xmlString); + $this->assertStringContainsString('old-online-issn', $xmlString); + $this->assertStringContainsString('old-print-issn', $xmlString); + $this->assertStringNotContainsString('New Journal Name', $xmlString); + $this->assertStringNotContainsString('new-online-issn', $xmlString); + $this->assertStringNotContainsString('new-print-issn', $xmlString); + } +}