Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #173 from mattwire/upgrader
Browse files Browse the repository at this point in the history
CRM-20192 Upgrader: Check for existing columns before trying to add new ones
  • Loading branch information
eileenmcnaughton authored Aug 3, 2018
2 parents 6006bd3 + a7ebf7e commit 09c254f
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions CRM/CiviDiscount/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,31 @@ class CRM_CiviDiscount_Upgrader extends CRM_CiviDiscount_Upgrader_Base {
*
*/
public function upgrade_2201() {
$this->ctx->log->info('Applying update 2201');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg_enabled TINYINT(1) DEFAULT 0 AFTER is_active');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg VARCHAR(255) AFTER discount_msg_enabled');
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('cividiscount_item', 'discount_msg_enabled')) {
$this->ctx->log->info('Skipped cividiscount update 2201. Column discount_msg_enabled already present on cividiscount_item table.');
}
else {
$this->ctx->log->info('Applying cividiscount update 2201. Adding discount_msg_enabled to the cividiscount_item table.');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg_enabled TINYINT(1) DEFAULT 0 AFTER is_active');
}
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('cividiscount_item', 'discount_msg')) {
$this->ctx->log->info('Skipped cividiscount update 2201. Column discount_msg already present on cividiscount_item table.');
}
else {
$this->ctx->log->info('Applying cividiscount update 2201. Adding discount_msg to the cividiscount_item table.');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg VARCHAR(255) AFTER discount_msg_enabled');
}
return TRUE;
}

public function upgrade_2202() {
$this->ctx->log->info('Applying update 2202');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN filters VARCHAR(255)');
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('cividiscount_item', 'filters')) {
$this->ctx->log->info('Skipped cividiscount update 2202. Column filters already present on cividiscount_item table.');
}
else {
$this->ctx->log->info('Applying cividiscount update 2202. Adding filters to the cividiscount_item table.');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN filters VARCHAR(255)');
}
return TRUE;
}

Expand All @@ -36,4 +52,4 @@ public function upgrade_2203() {
}
return TRUE;
}
}
}

0 comments on commit 09c254f

Please sign in to comment.