Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/main/9535 skip invalid submission files #9657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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