$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);
(@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;