-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fixProblemRevisions#149' into 'master'
Adds support to detect preprints that had the title page inserted in older releases See merge request softwares-pkp/plugins_ojs/folhaDeRostoDoPDF!5
- Loading branch information
Showing
24 changed files
with
344 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
import('plugins.generic.titlePageForPreprint.classes.GalleyAdapter'); | ||
import('plugins.generic.titlePageForPreprint.classes.TitlePageDAO'); | ||
|
||
class GalleyAdapterFactory { | ||
|
||
public function createGalleyAdapter($submission, $galley): GalleyAdapter { | ||
$submissionFile = $galley->getFile(); | ||
list($lastRevisionId, $lastRevisionPath) = $this->getLatestRevision($submissionFile->getId()); | ||
|
||
if($this->submissionFileHasNewRevisionWithoutTitlePage($submissionFile, $lastRevisionId)) { | ||
Services::get('submissionFile')->edit($submissionFile, [ | ||
'folhaDeRosto' => 'nao', | ||
], Application::get()->getRequest()); | ||
} | ||
|
||
return new GalleyAdapter($lastRevisionPath, $galley->getLocale(), $submissionFile->getId(), $lastRevisionId); | ||
} | ||
|
||
public function getLatestRevision($submissionFileId) { | ||
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); | ||
$revisions = $submissionFileDao->getRevisions($submissionFileId)->toArray(); | ||
$lastRevision = get_object_vars($revisions[0]); | ||
|
||
foreach($revisions as $revision){ | ||
$revision = get_object_vars($revision); | ||
if($revision['fileId'] > $lastRevision['fileId']) | ||
$lastRevision = $revision; | ||
} | ||
|
||
return [$lastRevision['fileId'], $lastRevision['path']]; | ||
} | ||
|
||
public function submissionFileHasNewRevisionWithoutTitlePage($submissionFile, $lastRevisionId): bool { | ||
if(!empty($submissionFile->getData('folhaDeRosto'))){ | ||
$revisionIds = $submissionFile->getData('revisoes'); | ||
$revisionIds = json_decode($revisionIds); | ||
|
||
if($lastRevisionId != end($revisionIds)) { | ||
$titlePageDao = new TitlePageDAO(); | ||
$numberOfRevisions = $titlePageDao->getNumberOfRevisions($submissionFile->getId()); | ||
|
||
if($numberOfRevisions != end($revisionIds)) { //Check for legacy cases | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
import('plugins.generic.titlePageForPreprint.classes.SubmissionPress'); | ||
import('plugins.generic.titlePageForPreprint.classes.SubmissionPressPKP'); | ||
import('plugins.generic.titlePageForPreprint.classes.SubmissionModel'); | ||
import('plugins.generic.titlePageForPreprint.classes.TranslatorPKP'); | ||
import('plugins.generic.titlePageForPreprint.classes.GalleyAdapterFactory'); | ||
|
||
class SubmissionPressFactory { | ||
|
||
public function createSubmissionPress($submission, $publication, $context): SubmissionPress { | ||
$logoPath = $this->getLogoPath($context); | ||
$dataPress = $this->getDataForPress($submission, $publication); | ||
$galleys = $publication->getData('galleys'); | ||
|
||
foreach ($galleys as $galley) { | ||
$galleyAdapterFactory = new GalleyAdapterFactory(); | ||
$submissionGalleys[] = $galleyAdapterFactory->createGalleyAdapter($submission, $galley); | ||
} | ||
|
||
return new SubmissionPressPKP( | ||
$logoPath, | ||
new SubmissionModel($dataPress['status'], $dataPress['doi'], $dataPress['doiJournal'], $dataPress['authors'], $dataPress['submissionDate'], $dataPress['publicationDate'], $dataPress['version'], $submissionGalleys), | ||
new TranslatorPKP($context, $submission, $publication) | ||
); | ||
} | ||
|
||
public function getLogoPath($context) { | ||
$publicFileManager = new PublicFileManager(); | ||
$filesPath = $publicFileManager->getContextFilesPath($context->getId()); | ||
$logoFilePath = $context->getLocalizedPageHeaderLogo()['uploadName']; | ||
|
||
return $filesPath . DIRECTORY_SEPARATOR . $logoFilePath; | ||
} | ||
|
||
private function getAuthors($publication) { | ||
$userGroupIds = array_map(function($author) { | ||
return $author->getData('userGroupId'); | ||
}, $publication->getData('authors')); | ||
$userGroups = array_map(function($userGroupId) { | ||
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); | ||
return $userGroupDao->getbyId($userGroupId); | ||
}, array_unique($userGroupIds)); | ||
|
||
return $publication->getAuthorString($userGroups); | ||
} | ||
|
||
private function getDataForPress($submission, $publication) { | ||
$data = array(); | ||
|
||
$data['doi'] = $publication->getStoredPubId('doi'); | ||
$data['doiJournal'] = $publication->getData('vorDoi'); | ||
$data['authors'] = $this->getAuthors($publication); | ||
$data['version'] = $publication->getData('version'); | ||
|
||
$dateSubmitted = strtotime($submission->getData('dateSubmitted')); | ||
$data['submissionDate'] = date('Y-m-d', $dateSubmitted); | ||
$datePublished = strtotime($publication->getData('datePublished')); | ||
$data['publicationDate'] = date('Y-m-d', $datePublished); | ||
|
||
$status = $publication->getData('relationStatus'); | ||
$relation = array(PUBLICATION_RELATION_NONE => 'publication.relation.none', PUBLICATION_RELATION_SUBMITTED => 'publication.relation.submitted', PUBLICATION_RELATION_PUBLISHED => 'publication.relation.published'); | ||
$data['status'] = ($status) ? ($relation[$status]) : (""); | ||
|
||
return $data; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
sources/SubmissionPressForTests.inc.php → classes/SubmissionPressForTests.inc.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
sources/SubmissionPressPKP.inc.php → classes/SubmissionPressPKP.inc.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* @file plugins/reports/titlePageForPreprint/classes/TitlePageDAO.inc.php | ||
* | ||
* @class TitlePageDAO | ||
* @ingroup plugins_generic_titlePageForPreprint | ||
* | ||
* Operations for retrieving data for the title page | ||
*/ | ||
|
||
import('lib.pkp.classes.db.DAO'); | ||
|
||
use Illuminate\Database\Capsule\Manager as Capsule; | ||
use Illuminate\Support\Collection; | ||
|
||
class TitlePageDAO extends DAO { | ||
|
||
public function getNumberOfRevisions(int $submissionFileId): int { | ||
$numberOfRevisions = Capsule::table('submission_file_revisions') | ||
->where('submission_file_id', $submissionFileId) | ||
->count(); | ||
|
||
return $numberOfRevisions; | ||
} | ||
|
||
} |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
sources/TranslatorForTests.inc.php → classes/TranslatorForTests.inc.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.