Add in Upgrade helper function and change style as per comments from Eileen
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 6 May 2017 06:50:18 +0000 (16:50 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 6 May 2017 06:50:18 +0000 (16:50 +1000)
CRM/Core/BAO/SchemaHandler.php
CRM/Upgrade/Incremental/Base.php
CRM/Upgrade/Incremental/php/FourSeven.php

index 51b5b77a87e797e951c7287ac34b3bd4df1ba4a4..1f4a93c17183aa47944bf064e20a19f508bf6f6f 100644 (file)
@@ -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;
     }
index 5ac12b23d6befb82f76d0b6a1dbb1e88862d661e..cef0d215efa926a51e1586e56ed379d094f9b2c4 100644 (file)
@@ -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
    *
index abe4aa65994284f8b82770d6bd099e2c6d9cebe1..1c764b3726625afa33cfbccd9bd014c4a6282643 100644 (file)
@@ -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`)