Skip to content

Commit

Permalink
Merge pull request #9657 from jonasraoni/bugfix/main/9535-skip-invali…
Browse files Browse the repository at this point in the history
…d-submission-files

Bugfix/main/9535 skip invalid submission files
  • Loading branch information
jonasraoni authored Jan 27, 2024
2 parents 79bcdb9 + 61b0e35 commit b139c4a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
37 changes: 37 additions & 0 deletions classes/migration/upgrade/v3_4_0/I9535_FixEmptyFileStage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @file classes/migration/upgrade/v3_4_0/I9535_FixEmptyFileStage.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I9535_FixEmptyFileStage.php
*
* @brief Redirect empty file stages to the SUBMISSION_FILE_SUBMISSION.
*
*/

namespace PKP\migration\upgrade\v3_4_0;

use Illuminate\Support\Facades\DB;
use PKP\install\DowngradeNotSupportedException;
use PKP\migration\Migration;

class I9535_FixEmptyFileStage extends Migration
{
public function up(): void
{
DB::table('submission_files')
// empty file_stage
->where('file_stage', 0)
// To \PKP\submissionFile\SubmissionFile::SUBMISSION_FILE_SUBMISSION
->update(['file_stage' => 2]);
}

public function down(): void
{
throw new DowngradeNotSupportedException();
}
}
3 changes: 3 additions & 0 deletions locale/en/manager.po
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,9 @@ msgstr ""
msgid "plugins.importexport.native.error.submissionFileWithoutRevision"
msgstr "The submission file {$id} was skipped because it does not have a valid revision."

msgid "plugins.importexport.native.error.submissionFileInvalidFileStage"
msgstr "The submission file {$id} was skipped because it does not have a valid file stage."

msgid "plugins.importexport.native.error.submissionFileRevisionMissing"
msgstr "The revision {$revision} of the submission file {$id} was skipped because the file was not found at the path \"{$path}\"."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public function createSubmissionFileNode(DOMDocument $doc, SubmissionFile $submi
$deployment = $this->getDeployment();
$context = $deployment->getContext();
$stageToName = array_flip($deployment->getStageNameStageIdMapping());

// Quit if the submission file has an invalid file stage
if (!isset($stageToName[$submissionFile->getFileStage()])) {
$deployment->addWarning(PKPApplication::ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getId(), __('plugins.importexport.native.error.submissionFileInvalidFileStage', ['id' => $submissionFile->getId()]));
return null;
}

$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
$genre = $genreDao->getById($submissionFile->getData('genreId'));
$uploaderUser = Repo::user()->get($submissionFile->getData('uploaderUserId'), true);
Expand Down

0 comments on commit b139c4a

Please sign in to comment.