From 8c748d50dd3c9105ad406c557f733544ece8e2b5 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 14 Jan 2017 17:40:06 +1100 Subject: [PATCH] CRM-18464 use safe drop foreign key function to resolve upgrade error and also drop Index with same name as foreign key being dropped if it exists --- CRM/Upgrade/Incremental/php/FourSeven.php | 16 ++++++++++++++++ CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index a1a3c58152..963908f00a 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -119,6 +119,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base * @param string $rev */ public function upgrade_4_7_alpha1($rev) { + $this->addTask('Drop action scheudle mapping foreign key', 'dropActionScheudleMappingForeignKey'); $this->addTask('Migrate \'on behalf of\' information to module_data', 'migrateOnBehalfOfInfo'); $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); $this->addTask(ts('Migrate Settings to %1', array(1 => $rev)), 'migrateSettings', $rev); @@ -780,6 +781,21 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_ return TRUE; } + /** + * CRM-18464 Check if Foreign key exists and also drop any index of same name accidentially created. + * + * @param \CRM_Queue_TaskContext $ctx + * + * @return bool + */ + public static function dropActionScheudleMappingForeignKey(CRM_Queue_TaskContext $ctx) { + CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_action_schedule', 'FK_civicrm_action_schedule_mapping_id'); + if (CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_action_schedule', 'FK_civicrm_action_schedule_mapping_id')) { + CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_action_schedule DROP INDEX FK_civicrm_action_schedule_mapping_id"); + } + return TRUE; + } + /** * CRM-18345 Don't delete mailing data on email/phone deletion * Implemented here in CRM-18526 diff --git a/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl index 7ef1d6af18..df1ad7d5c7 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl @@ -3,7 +3,6 @@ -- Add new columns for multilingual purpose ALTER TABLE `civicrm_action_schedule` ADD COLUMN `filter_contact_language` varchar(128) DEFAULT NULL COMMENT 'Used for multilingual installation'; ALTER TABLE `civicrm_action_schedule` ADD COLUMN `communication_language` varchar(8) DEFAULT NULL COMMENT 'Used for multilingual installation'; -ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_schedule_mapping_id`; ALTER TABLE `civicrm_action_schedule` MODIFY COLUMN mapping_id varchar(64); -- Q: Should we validate that local civicrm_action_mapping records have expected IDs? -- 2.25.1