From da1ecd739fff671ed33ad3b3799d80c845edbd07 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 29 Jun 2016 14:39:19 +1000 Subject: [PATCH] Shift add table to php to make use of checking if field already exists --- CRM/Upgrade/Incremental/php/FourSeven.php | 46 +++++++++++++++++++++ CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl | 15 ------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index 69005132e3..178c54d58f 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -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 * diff --git a/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl index b149b9e433..6c411d128a 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl @@ -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} -- 2.25.1