Skip to content

Commit

Permalink
Merge pull request #19773 from demeritcowboy/safe-foreignkey
Browse files Browse the repository at this point in the history
dev/core#2452 - Make upgrade to 5.36 more robust when creating foreign key
  • Loading branch information
eileenmcnaughton authored Mar 10, 2021
2 parents 401c947 + fb275f8 commit 57d6e6b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions CRM/Upgrade/Incremental/php/FiveThirtySix.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,24 @@ public function upgrade_5_36_alpha1(string $rev): void {
* @return bool
*/
public static function taskAddConstraints(CRM_Queue_TaskContext $ctx): bool {
CRM_Core_DAO::executeQuery("
ALTER TABLE `civicrm_saved_search`
ADD CONSTRAINT `FK_civicrm_saved_search_created_id`
FOREIGN KEY (`created_id`) REFERENCES `civicrm_contact` (`id`)
ON DELETE SET NULL,
ADD CONSTRAINT `FK_civicrm_saved_search_modified_id`
FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`)
ON DELETE SET NULL;
");
if (!self::checkFKExists('civicrm_saved_search', 'FK_civicrm_saved_search_created_id')) {
CRM_Core_DAO::executeQuery("
ALTER TABLE `civicrm_saved_search`
ADD CONSTRAINT `FK_civicrm_saved_search_created_id`
FOREIGN KEY (`created_id`) REFERENCES `civicrm_contact` (`id`)
ON DELETE SET NULL;
");
}

if (!self::checkFKExists('civicrm_saved_search', 'FK_civicrm_saved_search_modified_id')) {
CRM_Core_DAO::executeQuery("
ALTER TABLE `civicrm_saved_search`
ADD CONSTRAINT `FK_civicrm_saved_search_modified_id`
FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`)
ON DELETE SET NULL;
");
}

return TRUE;
}

Expand Down

0 comments on commit 57d6e6b

Please sign in to comment.