diff --git a/classes/messages/P1Pio.php b/classes/messages/P1Pio.php index 11e20b6..e811a65 100644 --- a/classes/messages/P1Pio.php +++ b/classes/messages/P1Pio.php @@ -6,7 +6,6 @@ use APP\plugins\generic\OASwitchboard\classes\exceptions\P1PioException; use PKP\db\DAORegistry; use APP\facades\Repo; -use PKP\facades\Locale; use PKP\decision\Decision; use PKP\plugins\PluginRegistry; @@ -152,27 +151,46 @@ public function getSubmissionDecisions(): array private function getFileId() { - $genreDao = DAORegistry::getDAO('GenreDAO'); - $articleTextGenreId = $genreDao->getByKey('SUBMISSION')->getId(); + $journal = DAORegistry::getDAO('JournalDAO')->getById($this->submission->getData('contextId')); + $galleys = $this->getArticleTextGalleys(); - $galleys = $this->submission->getGalleys(); + if (count($galleys) > 1) { + return $this->getFirstPrimaryLocaleGalleyFileId($galleys, $journal->getPrimaryLocale()); + } - $galleyFileId = []; + return empty($galleys) ? null : $galleys[0]->getData('submissionFileId'); + } + private function getFirstPrimaryLocaleGalleyFileId($galleys, $primaryLocale) + { foreach ($galleys as $galley) { - $submissionFileId = $galley->getData('submissionFileId'); - $genreId = $this->getGenreOfSubmissionFile($submissionFileId); - if ($genreId === $articleTextGenreId) { - if (Locale::getPrimaryLocale() == $galley->getLocale()) { - $galleyFileId[] = $submissionFileId; - } + if ($galley->getData('locale') === $primaryLocale) { + return $galley->getData('submissionFileId'); } } + } - return isset($galleyFileId[0]) ? $galleyFileId[0] : null; + private function getArticleTextGenreId(): int + { + return DAORegistry::getDAO('GenreDAO') + ->getByKey('SUBMISSION', $this->submission->getData('contextId')) + ->getId(); + } + + private function getArticleTextGalleys(): array + { + $articleTextGalleys = []; + foreach ($this->submission->getGalleys() as $galley) { + $submissionFileId = $galley->getData('submissionFileId'); + $genreId = $this->getGenreIdOfSubmissionFile($submissionFileId); + if ($genreId === $this->getArticleTextGenreId()) { + $articleTextGalleys[] = $galley; + } + } + return $articleTextGalleys; } - public function getGenreOfSubmissionFile($submissionFileId) + public function getGenreIdOfSubmissionFile($submissionFileId) { return Repo::submissionFile()->get($submissionFileId)->getData('genreId'); } diff --git a/tests/helpers/ObjectFactory.php b/tests/helpers/ObjectFactory.php index 11a1a1f..ab76ade 100644 --- a/tests/helpers/ObjectFactory.php +++ b/tests/helpers/ObjectFactory.php @@ -10,7 +10,6 @@ use APP\author\Author; use PKP\galley\Galley; use PKP\submissionFile\SubmissionFile; -use PKP\facades\Locale; use APP\core\Application; use APP\plugins\generic\OASwitchboard\classes\messages\P1Pio; use PKP\decision\Decision; @@ -47,7 +46,7 @@ public static function createTestAuthors($publication): array public static function createMockedJournal(PKPTestCase $testClass, $onlineIssn = null, $printIssn = null) { $journal = new Journal(); - $journal->setId(rand()); + $journal->setId(1); $journal->setName('Middle Earth papers', 'en_US'); if ($printIssn and $onlineIssn) { $journal->setData('onlineIssn', $onlineIssn); @@ -72,23 +71,11 @@ public static function createTestSubmission($journal, $hasPrimaryContactId = fal $galley = new Galley(); $galley->setId(rand()); $galley->setData('label', 'PDF'); - $galley->setLocale(Locale::getPrimaryLocale()); + $galley->setLocale($journal->getPrimaryLocale()); $submissionFile = new SubmissionFile(); $submissionFile->setId(9999); - $genreDao = DAORegistry::getDAO('GenreDAO'); - $articleTextGenreId = $genreDao->getByKey('SUBMISSION')->getId(); - $submissionFile->setData('genreId', $articleTextGenreId); - $submissionFile->setData('mimetype', 'application/pdf'); - $submissionFile->setData('submissionId', 456); - $submissionFile->setData('assocType', Application::ASSOC_TYPE_SUBMISSION_FILE); - $submissionFile->setData('assocId', $galley->getId()); - $submissionFile->setData('uploaderUserId', 1); - $submissionFile->setData('createdAt', '2021-01-01 00:00:00'); - $submissionFile->setData('fileStage', SubmissionFile::SUBMISSION_FILE_DEPENDENT); - $submissionFile->setData('fileId', 1234); - $submission = new Submission(); $submission->setId(456); $submission->setData('contextId', $journal->getId()); @@ -127,11 +114,11 @@ public static function createP1PioMock(PKPTestCase $testClass, $submission) { $P1PioMock = $testClass->getMockBuilder(P1Pio::class) ->setConstructorArgs([$submission]) - ->setMethods(['getGenreOfSubmissionFile', 'getSubmissionDecisions']) + ->setMethods(['getGenreIdOfSubmissionFile', 'getSubmissionDecisions']) ->getMock(); $P1PioMock->expects($testClass->any()) - ->method('getGenreOfSubmissionFile') + ->method('getGenreIdOfSubmissionFile') ->will($testClass->returnValue(1)); $decision = new Decision();