Skip to content

Commit

Permalink
pkp/pkp-lib#7599 Added migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Feb 19, 2022
1 parent 280f697 commit c668d23
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
@@ -0,0 +1,56 @@
<?php

/**
* @file classes/migration/upgrade/3_4_0/I7599_UpdateInvalidStageId.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I7599_UpdateInvalidStageId
* @brief Ensure there's no data assigned to the submission stage in order to address the issue pkp/pkp-lib#7599.
*/

namespace APP\migration\upgrade\v3_4_0;

use Exception;
use Illuminate\Support\Facades\DB;
use PKP\install\DowngradeNotSupportedException;

class I7599_UpdateInvalidStageId extends \PKP\migration\Migration
{
/**
* Run the migration.
*/
public function up(): void
{
// Ensure there's no data assigned to tables which would be risky to update by ourselves
$riskyTables = array_filter(
['review_round_files', 'review_assignments', 'edit_decisions', 'review_rounds'],
fn ($table) => DB::table($table)->where('stage_id', '<>', '5')->count() > 0
);
if (count($riskyTables)) {
throw new Exception(
'The upgrade is unable to proceed safely due to the existence of records using a'
. ' non-production stage (all records should have stage_id = 5) in the following'
. ' tables (the records must be updated/merged/removed manually before attempting to upgrade again): '
. implode(', ', $riskyTables)
);
}

// Update any stage to WORKFLOW_STAGE_ID_PRODUCTION
DB::statement('UPDATE submissions SET stage_id = 5 WHERE stage_id <> 5');
DB::statement('UPDATE queries SET stage_id = 5 WHERE stage_id <> 5');
// Remove records which don't have the stage_id equals to WORKFLOW_STAGE_ID_PRODUCTION
DB::statement('DELETE FROM email_templates_default WHERE stage_id <> 5');
DB::statement('DELETE FROM user_group_stage WHERE stage_id <> 5');
}

/**
* Reverse the downgrades
*/
public function down(): void
{
throw new DowngradeNotSupportedException();
}
}
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Expand Up @@ -42,6 +42,7 @@
<migration class="PKP\migration\upgrade\v3_4_0\I7167_RemoveDuplicatedUserSettingsAndDeprecatedFields" />
<migration class="APP\migration\upgrade\v3_4_0\I7264_UpdateEmailTemplates"/>
<migration class="APP\migration\upgrade\v3_4_0\I7014_DoiMigration"/>
<migration class="APP\migration\upgrade\v3_4_0\I7599_UpdateInvalidStageId"/>
<data file="dbscripts/xml/upgrade/3.4.0_preupdate_email_templates.xml" />
<note file="docs/release-notes/README-3.4.0" />
</upgrade>
Expand Down

0 comments on commit c668d23

Please sign in to comment.