Shift add table to php to make use of checking if field already exists
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 29 Jun 2016 04:39:19 +0000 (14:39 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 29 Jun 2016 04:39:19 +0000 (14:39 +1000)
CRM/Upgrade/Incremental/php/FourSeven.php
CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl

index 69005132e3b61bfec244de87cae45b397bb524d5..178c54d58f8c0f2bae8db7dc02bedbdf5aada1d9 100644 (file)
@@ -210,6 +210,16 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base
     $this->addTask('Upgrade mailing foreign key constraints', 'upgradeMailingFKs');
   }
 
+  /**
+   * Upgrade function.
+   *
+   * @param string $rev
+   */
+  public function upgrade_4_7_9($rev) {
+    $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+    $this->addTask('Upgrade Add Help Pre and Post Fields to price value table', 'addHelpPreAndHelpPostFieldsPriceFieldValue');
+  }
+
   /*
    * Important! All upgrade functions MUST call the 'runSql' task.
    * Uncomment and use the following template for a new upgrade version
@@ -619,6 +629,42 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_
     return TRUE;
   }
 
+  /**
+   * CRM-12252 Add Help Pre and Help Post Fields for Price Field Value Table.
+   *
+   * @param \CRM_Queue_TaskContext $ctx
+   *
+   * @return bool
+   */
+  public function addHelpPreAndHelpPostFieldsPriceFieldValue(CRM_Queue_TaskContext $ctx) {
+    $domain = new CRM_Core_DAO_Domain();
+    $domain->find(TRUE);
+    if ($domain->locales) {
+      $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
+      foreach ($locales as $locale) {
+        if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_pre_' . $locale)) {
+          CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_price_field_value`
+            ADD COLUMN `help_pre_' . $locale . '` text COLLATE utf8_unicode_ci COMMENT "Price field option pre help text."');
+        }
+        if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_post_' . $locale)) {
+          CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_price_field_value`
+            ADD COLUMN `help_post_' . $locale . '` text COLLATE utf8_unicode_ci COMMENT "Price field option post help text."');
+        }
+      }
+    }
+    else {
+      if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_pre')) {
+        CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_price_field_value`
+          ADD COLUMN `help_pre` text COLLATE utf8_unicode_ci COMMENT "Price field option pre help text."');
+      }
+      if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_post')) {
+        CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_price_field_value`
+          ADD COLUMN `help_post` text COLLATE utf8_unicode_ci COMMENT "Price field option post help text."');
+      }
+    }
+    return TRUE;
+  }
+
   /**
    * Remove a foreign key from a table if it exists
    *
index b149b9e4331352354e3669b4f6a2ff20a3c2e670..6c411d128a3b10a0e6543d051ebbeebbca0d79b3 100644 (file)
@@ -53,18 +53,3 @@ INSERT INTO `civicrm_entity_financial_account`
 VALUES
   ('civicrm_financial_type', @financial_type_id_ef, @option_value_rel_id_dr, @financial_account_id_dref),
   ('civicrm_financial_type', @financial_type_id_md, @option_value_rel_id_dr, @financial_account_id_drmd);
-
---CRM-12252 Add in help_pre and help_post colmns to price field value table
-{if $multilingual}
-  {foreach from=$locales item=locale}
-    ALTER TABLE `civicrm_price_field_value`
-    ADD COLUMN `help_pre_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.';
-    ALTER TABLE `civicrm_price_field_value`
-    ADD `help_post_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option post field help.';
-  {/foreach}
-{else}
-  ALTER TABLE `civicrm_price_field_value`
-  ADD COLUMN `help_pre` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.';
-  ALTER TABLE `civicrm_price_field_value`
-  ADD `help_post` text COLLATE utf8_unicode_ci COMMENT 'Price field option post field help.';
-{/if}