Skip to content

Commit

Permalink
Move upgrade code to correct version
Browse files Browse the repository at this point in the history
See #20553
  • Loading branch information
colemanw committed Jun 17, 2021
1 parent ffd6744 commit 930c05e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
40 changes: 20 additions & 20 deletions CRM/Upgrade/Incremental/php/FiveForty.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
// }
}

/*
* Important! All upgrade functions MUST add a 'runSql' task.
* Uncomment and use the following template for a new upgrade version
* (change the x in the function name):
*/
public function upgrade_5_40_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('core-issue#2486 - Add product_id foreign key to civicrm_contribution_product', 'addContributionProductFK');
}

// /**
// * Upgrade function.
// *
// * @param string $rev
// */
// public function upgrade_5_0_x($rev) {
// $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
// $this->addTask('Do the foo change', 'taskFoo', ...);
// // Additional tasks here...
// // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }
/**
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*/
public static function addContributionProductFK(CRM_Queue_TaskContext $ctx): bool {
if (!self::checkFKExists('civicrm_contribution_product', 'FK_civicrm_contribution_product_product_id')) {
CRM_Core_DAO::executeQuery("
ALTER TABLE `civicrm_contribution_product`
ADD CONSTRAINT `FK_civicrm_contribution_product_product_id`
FOREIGN KEY (`product_id`) REFERENCES `civicrm_product` (`id`)
ON DELETE CASCADE;
", [], TRUE, NULL, FALSE, FALSE);
}

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
return TRUE;
}

}
23 changes: 0 additions & 23 deletions CRM/Upgrade/Incremental/php/FiveThirtyNine.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,6 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
// }
}

public function upgrade_5_39_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('core-issue#2486 - Add product_id foreign key to civicrm_contribution_product', 'addContributionProductFK');
}

/**
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*/
public static function addContributionProductFK(CRM_Queue_TaskContext $ctx): bool {
if (!self::checkFKExists('civicrm_contribution_product', 'FK_civicrm_contribution_product_product_id')) {
CRM_Core_DAO::executeQuery("
ALTER TABLE `civicrm_contribution_product`
ADD CONSTRAINT `FK_civicrm_contribution_product_product_id`
FOREIGN KEY (`product_id`) REFERENCES `civicrm_product` (`id`)
ON DELETE CASCADE;
", [], TRUE, NULL, FALSE, FALSE);
}

return TRUE;
}

/*
* Important! All upgrade functions MUST add a 'runSql' task.
* Uncomment and use the following template for a new upgrade version
Expand Down

0 comments on commit 930c05e

Please sign in to comment.