Skip to content

Commit

Permalink
CRM-18464 use safe drop foreign key function to resolve upgrade error…
Browse files Browse the repository at this point in the history
… and also drop Index with same name as foreign key being dropped if it exists
  • Loading branch information
seamuslee001 committed Jan 14, 2017
1 parent 7ae669b commit a0c0a65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 16 additions & 0 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
* @param string $rev
*/
public function upgrade_4_7_alpha1($rev) {
$this->addTask('Drop action schedule mapping foreign key', 'dropActionScheudleMappingForeignKey');
$this->addTask('Migrate \'on behalf of\' information to module_data', 'migrateOnBehalfOfInfo');
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
$this->addTask(ts('Migrate Settings to %1', array(1 => $rev)), 'migrateSettings', $rev);
Expand Down Expand Up @@ -780,6 +781,21 @@ public static function addHelpPreAndHelpPostFieldsPriceFieldValue(CRM_Queue_Task
return TRUE;
}

/**
* CRM-18464 Check if Foreign key exists and also drop any index of same name accidentially created.
*
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*/
public static function dropActionScheudleMappingForeignKey(CRM_Queue_TaskContext $ctx) {
CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_action_schedule', 'FK_civicrm_action_schedule_mapping_id');
if (CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_action_schedule', 'FK_civicrm_action_schedule_mapping_id')) {
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_action_schedule DROP INDEX FK_civicrm_action_schedule_mapping_id");
}
return TRUE;
}

/**
* CRM-18345 Don't delete mailing data on email/phone deletion
* Implemented here in CRM-18526
Expand Down
1 change: 0 additions & 1 deletion CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-- Add new columns for multilingual purpose
ALTER TABLE `civicrm_action_schedule` ADD COLUMN `filter_contact_language` varchar(128) DEFAULT NULL COMMENT 'Used for multilingual installation';
ALTER TABLE `civicrm_action_schedule` ADD COLUMN `communication_language` varchar(8) DEFAULT NULL COMMENT 'Used for multilingual installation';
ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_schedule_mapping_id`;
ALTER TABLE `civicrm_action_schedule` MODIFY COLUMN mapping_id varchar(64);
-- Q: Should we validate that local civicrm_action_mapping records have expected IDs?

Expand Down

0 comments on commit a0c0a65

Please sign in to comment.