Skip to content

Commit

Permalink
Shift add table to php to make use of checking if field already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Jun 23, 2016
1 parent 3756b54 commit bfb27e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
46 changes: 46 additions & 0 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public function upgrade_4_7_8($rev) {
$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
Expand Down Expand Up @@ -600,6 +610,42 @@ public function addDeletedByMergeActivityType(CRM_Queue_TaskContext $ctx) {
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
*
Expand Down
15 changes: 0 additions & 15 deletions CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,3 @@ ALTER TABLE civicrm_financial_account

ALTER TABLE civicrm_contribution
ADD `revenue_recognition_date` datetime DEFAULT NULL COMMENT 'Stores the date when revenue should be recognized.';

--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}

0 comments on commit bfb27e0

Please sign in to comment.