From 930c05e087ba98388489bc80c638acfab3f4597c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 17 Jun 2021 09:27:30 -0400 Subject: [PATCH] Move upgrade code to correct version See https://github.com/civicrm/civicrm-core/pull/20553 --- CRM/Upgrade/Incremental/php/FiveForty.php | 40 +++++++++---------- .../Incremental/php/FiveThirtyNine.php | 23 ----------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveForty.php b/CRM/Upgrade/Incremental/php/FiveForty.php index 8ccfaf1f70..a27a780970 100644 --- a/CRM/Upgrade/Incremental/php/FiveForty.php +++ b/CRM/Upgrade/Incremental/php/FiveForty.php @@ -49,27 +49,27 @@ class CRM_Upgrade_Incremental_php_FiveForty extends CRM_Upgrade_Incremental_Base // } } - /* - * Important! All upgrade functions MUST add a 'runSql' task. - * Uncomment and use the following template for a new upgrade version - * (change the x in the function name): - */ + public function upgrade_5_40_alpha1($rev) { + $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('core-issue#2486 - Add product_id foreign key to civicrm_contribution_product', 'addContributionProductFK'); + } - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } + /** + * @param \CRM_Queue_TaskContext $ctx + * + * @return bool + */ + public static function addContributionProductFK(CRM_Queue_TaskContext $ctx): bool { + if (!self::checkFKExists('civicrm_contribution_product', 'FK_civicrm_contribution_product_product_id')) { + CRM_Core_DAO::executeQuery(" + ALTER TABLE `civicrm_contribution_product` + ADD CONSTRAINT `FK_civicrm_contribution_product_product_id` + FOREIGN KEY (`product_id`) REFERENCES `civicrm_product` (`id`) + ON DELETE CASCADE; + ", [], TRUE, NULL, FALSE, FALSE); + } - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + return TRUE; + } } diff --git a/CRM/Upgrade/Incremental/php/FiveThirtyNine.php b/CRM/Upgrade/Incremental/php/FiveThirtyNine.php index b3e1d61512..4ad6125a39 100644 --- a/CRM/Upgrade/Incremental/php/FiveThirtyNine.php +++ b/CRM/Upgrade/Incremental/php/FiveThirtyNine.php @@ -49,29 +49,6 @@ class CRM_Upgrade_Incremental_php_FiveThirtyNine extends CRM_Upgrade_Incremental // } } - public function upgrade_5_39_alpha1($rev) { - $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - $this->addTask('core-issue#2486 - Add product_id foreign key to civicrm_contribution_product', 'addContributionProductFK'); - } - - /** - * @param \CRM_Queue_TaskContext $ctx - * - * @return bool - */ - public static function addContributionProductFK(CRM_Queue_TaskContext $ctx): bool { - if (!self::checkFKExists('civicrm_contribution_product', 'FK_civicrm_contribution_product_product_id')) { - CRM_Core_DAO::executeQuery(" - ALTER TABLE `civicrm_contribution_product` - ADD CONSTRAINT `FK_civicrm_contribution_product_product_id` - FOREIGN KEY (`product_id`) REFERENCES `civicrm_product` (`id`) - ON DELETE CASCADE; - ", [], TRUE, NULL, FALSE, FALSE); - } - - return TRUE; - } - /* * Important! All upgrade functions MUST add a 'runSql' task. * Uncomment and use the following template for a new upgrade version -- 2.25.1