Skip to content

Commit

Permalink
Merge branch 'fixManuscriptID-851' into 'main'
Browse files Browse the repository at this point in the history
Fix and improve the Manunscript ID retrieval from submission Galley

See merge request softwares-pkp/plugins_ojs/OASwitchboard!25
  • Loading branch information
YvesLepidus committed Jul 30, 2024
2 parents 7cac55c + f697614 commit 35c8d8f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
44 changes: 31 additions & 13 deletions classes/messages/P1Pio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
}
Expand Down
21 changes: 4 additions & 17 deletions tests/helpers/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 35c8d8f

Please sign in to comment.