From 61612722ef77bd35db5810ec5d5b3a6fd6f31882 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 26 Jun 2017 21:15:04 +1000 Subject: [PATCH] CRM-20771 Ensure that addColumn can handle translatable columns --- CRM/Upgrade/Incremental/Base.php | 27 ++++++++++++++++++----- CRM/Upgrade/Incremental/php/FourSeven.php | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 1aab7f9511..ac5ba686b0 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -148,15 +148,32 @@ class CRM_Upgrade_Incremental_Base { * @param string $table * @param string $column * @param string $properties + * @param bool $localizable is this a field that should be localized * @return bool */ - public static function addColumn($ctx, $table, $column, $properties) { - if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists($table, $column)) { - CRM_Core_DAO::executeQuery("ALTER TABLE `$table` ADD COLUMN `$column` $properties", - array(), TRUE, NULL, FALSE, FALSE); - } + public static function addColumn($ctx, $table, $column, $properties, $localizable = FALSE) { $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); + $queries = array(); + if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists($table, $column)) { + if ($domain->locales) { + if ($localizable) { + $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); + foreach ($locales as $locale) { + $queries[] = "ALTER TABLE `$table` ADD COLUMN `{$column}_{$locale}` $properties"; + } + } + else { + $queries[] = "ALTER TABLE `$table` ADD COLUMN `$column` $properties"; + } + } + else { + $queries[] = "ALTER TABLE `$table` ADD COLUMN `$column` $properties"; + } + foreach ($queries as $query) { + CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); + } + } if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL); diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index f0e601ae77..cd2c009d13 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -343,7 +343,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base } } $this->addTask('CRM-19961 - Add domain_id column to civicrm_sms_provider', 'addColumn', - 'civicrm_sms_provider', 'domain_id', 'int(10) unsigned', "Which Domain is this sms provier for"); + 'civicrm_sms_provider', 'domain_id', "int(10) unsigned COMMENT 'Which Domain is this sms provier for'"); $this->addTask('CRM-19961 - Populate domain id table and perhaps add foreign key', 'populateSMSProviderDomainId'); $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); $this->addTask('CRM-16633 - Add "Change Case Subject" activity', 'addChangeCaseSubjectActivityType'); -- 2.25.1