From: JKingsnorth Date: Mon, 4 Sep 2017 13:20:10 +0000 (+0100) Subject: CRM-20935 Remove related profile links when event deleted X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=52b54dda237fac322e29c6b9d84b9fdc37152602;p=civicrm-core.git CRM-20935 Remove related profile links when event deleted --- diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 65e6778455..6bc5fe3825 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1031,7 +1031,6 @@ ORDER BY civicrm_custom_group.weight, ); // create select - $select = "SELECT"; $s = array(); foreach ($tableData as $tableName => $tableColumn) { foreach ($tableColumn as $columnName) { diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 41cf64598f..d9a653736e 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -186,16 +186,27 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event { $extends = array('event'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); foreach ($groupTree as $values) { - $query = "DELETE FROM " . $values['table_name'] . " WHERE entity_id = " . $id; - - $params = array( - 1 => array($values['table_name'], 'string'), - 2 => array($id, 'integer'), - ); - - CRM_Core_DAO::executeQuery($query); + $query = "DELETE FROM %1 WHERE entity_id = %2"; + CRM_Core_DAO::executeQuery($query, array( + 1 => array($values['table_name'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES), + 2 => array($id, 'Integer'), + )); } + // 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.25.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.25.mysql.tpl index a8e4087635..7bb3bcebaa 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.25.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.25.mysql.tpl @@ -13,3 +13,10 @@ INSERT INTO civicrm_option_value (option_group_id, {localize field='label'}label (@option_group_id_env, {localize}'{ts escape="sql"}Production{/ts}'{/localize}, 'Production', 'Production', NULL, 0, 1, 1, {localize}'{ts escape="sql"}Production Environment{/ts}'{/localize}, 0, 0, 1, NULL, NULL), (@option_group_id_env, {localize}'{ts escape="sql"}Staging{/ts}'{/localize}, 'Staging', 'Staging', NULL, 0, NULL, 2, {localize}'{ts escape="sql"}Staging Environment{/ts}'{/localize}, 0, 0, 1, NULL, NULL), (@option_group_id_env, {localize}'{ts escape="sql"}Development{/ts}'{/localize}, 'Development', 'Development', NULL, 0, NULL, 3, {localize}'{ts escape="sql"}Development Environment{/ts}'{/localize}, 0, 0, 1, NULL, NULL); + +-- 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;