Skip to content
Open
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
36 changes: 36 additions & 0 deletions classes/migration/upgrade/v3_4_0/I7725_DecisionConstantsUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @file classes/migration/upgrade/v3_4_0/I7725_DecisionConstantsUpdate.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I7725_DecisionConstantsUpdate
*
* @brief Editorial decision constant sync up across all application
*
* @see https://github.com/pkp/pkp-lib/issues/7725
*/

namespace APP\migration\upgrade\v3_4_0;

class I7725_DecisionConstantsUpdate extends \PKP\migration\upgrade\v3_4_0\I7725_DecisionConstantsUpdate
{
/**
* Get the decisions constants mappings
*
* OPS only has 2 decisions at PRODUCTION stage: INITIAL_DECLINE and REVERT_DECLINE.
* No stage_id filtering needed: only 2 unique values with no collision risk,
* and the parent class's updated_at tracking prevents any issues.
* See https://github.com/pkp/pkp-lib/issues/12357
*/
public function getDecisionMappings(): array
{
return [
['current_value' => 9, 'updated_value' => 8], // INITIAL_DECLINE
['current_value' => 17, 'updated_value' => 16], // REVERT_INITIAL_DECLINE (was REVERT_DECLINE in 3.3)
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
*
* @brief Fixed the missing decisions data in stages
*
* @see https://github.com/pkp/pkp-lib/issues/11241
* @see https://github.com/pkp/pkp-lib/issues/11241
* https://github.com/pkp/pkp-lib/issues/9533
*/

namespace APP\migration\upgrade\v3_5_0;

use APP\core\Application;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use PKP\install\DowngradeNotSupportedException;

class I11241_MissingDecisionConstantsUpdate extends \PKP\migration\upgrade\v3_4_0\I7725_DecisionConstantsUpdate
{
/**
Expand All @@ -27,17 +32,95 @@ public function getDecisionMappings(): array
return [
// \PKP\decision\Decision::INITIAL_DECLINE
[
'stage_id' => WORKFLOW_STAGE_ID_PRODUCTION,
'stage_id' => [WORKFLOW_STAGE_ID_PRODUCTION],
'current_value' => 9,
'updated_value' => 8,
],
// \PKP\decision\Decision::REVERT_DECLINE to \PKP\decision\Decision::REVERT_INITIAL_DECLINE
// \PKP\decision\Decision::REVERT_INITIAL_DECLINE
// Was REVERT_DECLINE (17) in OPS 3.3, maps to REVERT_INITIAL_DECLINE (16) in 3.4
// \PKP\decision\Decision::REVERT_DECLINE removed in 3.4
[
'stage_id' => WORKFLOW_STAGE_ID_PRODUCTION,
'stage_id' => [WORKFLOW_STAGE_ID_PRODUCTION],
'current_value' => 17,
'updated_value' => 16,
]
],
];
}

/**
* Run the migrations.
*/
public function up(): void
{
// If the first installed version is 3.4.0+
// nothing to do and return
$firstInstalledVersion = DB::table('versions')
->where('product', Application::get()->getName())
->where('product_type', 'core')
->orderBy('date_installed')
->first();

if ($firstInstalledVersion->major == 3 && $firstInstalledVersion->minor == 4) {
return;
}

// Get the current version from which the upgrade is happening
$currentVersion = DB::table('versions')
->where('product', Application::get()->getName())
->where('product_type', 'core')
->where('current', 1)
->first();

// If NOT upgrading from 3.4.0-*, then fixed migration \APP\migration\upgrade\v3_4_0\I7725_DecisionConstantsUpdate
// have the new fix in place and rest of the code does not need to execute
if ($currentVersion->major == 3 && $currentVersion->minor != 4) {
return;
}

// If upgrading from 3.4.0-11 or above, then we have a fix applied also for it
// at https://github.com/pkp/pkp-lib/issues/12140
// so nothing to do and return
if ($currentVersion->major == 3 && $currentVersion->minor == 4 && $currentVersion->build >= 11) {
return;
}

// Upgrading from version range of 3.4.0-0 to 3.4.0-10
// Need to figure out the first installed date of 3.4.0-*
// Then need to update the decisions made before the first version of 3.4.0-* installed
$firstVersionOf34 = DB::table('versions')
->where('product', Application::get()->getName())
->where('product_type', 'core')
->where('major', 3)
->where('minor', 4)
->orderBy('date_installed')
->first();

$this->configureUpdatedAtColumn();

collect($this->getDecisionMappings())
->each(
fn ($decisionMapping) => DB::table('edit_decisions')
->when(
isset($decisionMapping['stage_id']) && !empty($decisionMapping['stage_id']),
fn ($query) => $query->whereIn('stage_id', $decisionMapping['stage_id'])
)
->where('decision', $decisionMapping['current_value'])
->whereNull('updated_at')
->where('date_decided', '<', $firstVersionOf34->date_installed)
->update([
'decision' => $decisionMapping['updated_value'],
'updated_at' => Carbon::now(),
])
);

$this->removeUpdatedAtColumn();
}

/**
* Reverse the migrations.
*/
public function down(): void
{
throw new DowngradeNotSupportedException();
}
}
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<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\I7265_EditorialDecisions"/>
<migration class="APP\migration\upgrade\v3_4_0\I7725_DecisionConstantsUpdate"/>
<migration class="APP\migration\upgrade\v3_4_0\I5774_SetRelationVariables"/>
<migration class="PKP\migration\upgrade\v3_4_0\I7624_StrftimeDeprecation"/>
<migration class="PKP\migration\upgrade\v3_4_0\I7592_RemoveUnusedEmailTemplates"/>
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Loading