From 1f46cfe286c248fb2c649f70d40e888d4fe97933 Mon Sep 17 00:00:00 2001 From: JKingsnorth Date: Fri, 21 Jul 2017 13:56:37 +0100 Subject: [PATCH] CRM-20935 Remove related profile links when event deleted --- CRM/Event/BAO/Event.php | 14 ++++++++++++++ CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 41cf64598fde..be683c96e095 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -196,6 +196,20 @@ public static function del($id) { CRM_Core_DAO::executeQuery($query); } + // Clean up references to profiles used by the event (CRM-20935) + $ufJoinParams = array( + 'module' => 'CiviEvent', + 'entity_table' => 'civicrm_event', + 'entity_id' => $id, + ); + CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); + $ufJoinParams = array( + 'module' => 'CiviEvent_Additional', + 'entity_table' => 'civicrm_event', + 'entity_id' => $id, + ); + CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); + // price set cleanup, CRM-5527 CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $id); diff --git a/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl index dbedca1b2f09..10bb6ae1924a 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl @@ -41,3 +41,10 @@ ON price_field.price_field_id = cpf.id LEFT JOIN civicrm_price_set ps ON ps.id = cpf.price_set_id SET cpf.is_active = 1 WHERE ps.is_quick_config = 1 AND cpf.is_active = 0; + +-- CRM-20935 Clean up orphaned profile links for deleted events +DELETE civicrm_uf_join +FROM civicrm_uf_join +LEFT JOIN civicrm_event e on civicrm_uf_join.entity_id = e.id +WHERE (civicrm_uf_join.module = 'CiviEvent' OR civicrm_uf_join.module = 'CiviEvent_Additional') +AND e.id IS NULL;