Skip to content

Commit

Permalink
pkp#7505 Support Versioning for SubmissionFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Nov 24, 2023
1 parent ea238b7 commit dcf051b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ public function version(Publication $publication): int
$citationDao->importCitations($newPublication->getId(), $newPublication->getData('citationsRaw'));
}

$jatsFile = Repo::submissionFile()
->getJatsFiles($publication->getData('submissionId'), $publication->getId());

if ($jatsFile) {
Repo::submissionFile()
->versionSubmissionFile($jatsFile, $newPublication);
}

$newPublication = Repo::publication()->get($newPublication->getId());

Hook::call('Publication::version', [&$newPublication, $publication]);
Expand Down
43 changes: 43 additions & 0 deletions classes/submissionFile/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,49 @@ public function addJatsFile(
return $submissionFile;
}

/**
* Can be used to copy a SubmissionFile to another SubmissionFile along with the corresponding file
*/
public function versionSubmissionFile(
SubmissionFile $submissionFile,
Publication $newPublication
): SubmissionFile
{
$newSubmissionFile = clone $submissionFile;

$oldFileId = $submissionFile->getData('fileId');

$oldFile = Services::get('file')->get($oldFileId);

$submission = Repo::submission()->get($newPublication->getData('submissionId'));

$fileManager = new FileManager();
$extension = $fileManager->parseFileExtension($oldFile->path);

$submissionDir = Repo::submissionFile()
->getSubmissionDir(
$submission->getData('contextId'),
$newPublication->getData('submissionId')
);

$newFileId = Services::get('file')->add(
Config::getVar('files', 'files_dir') . '/' . $oldFile->path,
$submissionDir . '/' . uniqid() . '.' . $extension
);

$newSubmissionFile->setData('id', null);
$newSubmissionFile->setData('assocId', $newPublication->getId());
$newSubmissionFile->setData('fileId', $newFileId);

$submissionFileId = Repo::submissionFile()
->add($newSubmissionFile);

$submissionFile = Repo::submissionFile()
->get($submissionFileId);

return $submissionFile;
}

/**
* Function to get the Context's genres
*/
Expand Down

0 comments on commit dcf051b

Please sign in to comment.