diff --git a/classes/migration/upgrade/v3_4_0/I7725_DecisionConstantsUpdate.php b/classes/migration/upgrade/v3_4_0/I7725_DecisionConstantsUpdate.php new file mode 100644 index 0000000000..4fc2039807 --- /dev/null +++ b/classes/migration/upgrade/v3_4_0/I7725_DecisionConstantsUpdate.php @@ -0,0 +1,36 @@ + 9, 'updated_value' => 8], // INITIAL_DECLINE + ['current_value' => 17, 'updated_value' => 16], // REVERT_INITIAL_DECLINE (was REVERT_DECLINE in 3.3) + ]; + } +} diff --git a/classes/migration/upgrade/v3_5_0/I11241_MissingDecisionConstantsUpdate.php b/classes/migration/upgrade/v3_5_0/I11241_MissingDecisionConstantsUpdate.php index c3538f6791..a54b81603a 100644 --- a/classes/migration/upgrade/v3_5_0/I11241_MissingDecisionConstantsUpdate.php +++ b/classes/migration/upgrade/v3_5_0/I11241_MissingDecisionConstantsUpdate.php @@ -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 { /** @@ -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(); + } } diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml index c6f4b6886e..b02901bfbf 100644 --- a/dbscripts/xml/upgrade.xml +++ b/dbscripts/xml/upgrade.xml @@ -40,6 +40,7 @@ + diff --git a/lib/pkp b/lib/pkp index 200d345b07..0ede430547 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 200d345b072e02ce91abecb0b9f9ab8e64ceea64 +Subproject commit 0ede43054775f9d676dd1882e0d8e49813af020e