From 27e82c248d3e6878a4a32f6542d6cf092229bea7 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 6 May 2017 16:50:18 +1000 Subject: [PATCH] Add in Upgrade helper function and change style as per comments from Eileen --- CRM/Core/BAO/SchemaHandler.php | 9 +++------ CRM/Upgrade/Incremental/Base.php | 9 +++++++++ CRM/Upgrade/Incremental/php/FourSeven.php | 6 ++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CRM/Core/BAO/SchemaHandler.php b/CRM/Core/BAO/SchemaHandler.php index 51b5b77a87..1f4a93c171 100644 --- a/CRM/Core/BAO/SchemaHandler.php +++ b/CRM/Core/BAO/SchemaHandler.php @@ -646,7 +646,6 @@ MODIFY {$columnName} varchar( $length ) * @return bool TRUE if FK is found */ public static function checkFKExists($table_name, $constraint_name) { - $found = FALSE; $config = CRM_Core_Config::singleton(); $dbUf = DB::parseDSN($config->dsn); $query = " @@ -664,9 +663,9 @@ MODIFY {$columnName} varchar( $length ) $dao = CRM_Core_DAO::executeQuery($query, $params); if ($dao->fetch()) { - $found = TRUE; + return TRUE; } - return $found; + return FALSE; } /** @@ -678,9 +677,7 @@ MODIFY {$columnName} varchar( $length ) * @return bool */ public static function safeRemoveFK($table_name, $constraint_name) { - $check = self::checkFKExists($table_name, $constraint_name); - - if ($check) { + if (self::checkFKExists($table_name, $constraint_name)) { CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", array()); return TRUE; } diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 5ac12b23d6..cef0d215ef 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -132,6 +132,15 @@ class CRM_Upgrade_Incremental_Base { return TRUE; } + /** + * @param string $table_name + * @param string $constraint_name + * @return bool + */ + public static function checkFKExists($table_name, $constraint_name) { + return CRM_Core_BAO_SchemaHandler::checkFKExists($table_name, $constraint_name); + } + /** * Add a column to a table if it doesn't already exist * diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index abe4aa6599..1c764b3726 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -1093,8 +1093,7 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_ if ($count = 1) { CRM_Core_DAO::executeQuery("UPDATE civicrm_sms_provider SET domain_id = (SELECT id FROM civicrm_domain)"); } - $check = CRM_Core_BAO_SchemaHandler::checkFKExists('civicrm_sms_provider', 'FK_civicrm_sms_provider_domain_id'); - if (!$check) { + if (!parent::checkFKExists('civicrm_sms_provider', 'FK_civicrm_sms_provider_domain_id')) { CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 0;"); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_sms_provider` ADD CONSTRAINT FK_civicrm_sms_provider_domain_id @@ -1129,8 +1128,7 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_ * CRM-19986 fix schema differnces in civicrm_action_schedule */ public static function fixSchemaOnCiviCRMActionSchedule() { - $check = CRM_Core_BAO_SchemaHandler::checkFKExists('civicrm_action_schedule', 'FK_civicrm_action_schedule_sms_template_id'); - if (!$check) { + if (!parent::checkFKExists('civicrm_action_schedule', 'FK_civicrm_action_schedule_sms_template_id')) { CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_action_schedule` ADD CONSTRAINT FK_civicrm_action_schedule_sms_template_id FOREIGN KEY (`sms_template_id`) REFERENCES `civicrm_msg_template`(`id`) -- 2.25.1