prevent deletion of current revisions
authordemeritcowboy <demeritcowboy@hotmail.com>
Tue, 6 Dec 2022 12:51:29 +0000 (07:51 -0500)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Tue, 6 Dec 2022 19:21:22 +0000 (14:21 -0500)
CRM/Upgrade/Incremental/php/FiveFiftySeven.php

index 67bcc73df27dd0f207cc8e5dfb62830b19aaf5c5..88939c3808703ddc24bd08f2f7ff1d186611b4a4 100644 (file)
@@ -37,7 +37,14 @@ class CRM_Upgrade_Incremental_php_FiveFiftySeven extends CRM_Upgrade_Incremental
    */
   public function upgrade_5_57_alpha1($rev): void {
     $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+    $this->addTask('Fix dangerous delete cascade', 'fixDeleteCascade');
     $this->addExtensionTask('Enable SearchKit extension', ['org.civicrm.search_kit'], 1100);
   }
 
+  public static function fixDeleteCascade($ctx): bool {
+    CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_activity', 'FK_civicrm_activity_original_id');
+    CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_activity` ADD CONSTRAINT `FK_civicrm_activity_original_id` FOREIGN KEY (`original_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE SET NULL');
+    return TRUE;
+  }
+
 }