From a47a0396c3ad59ec9dac78aac66ed7fe9f931c0c Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 5 Sep 2023 17:34:15 -0400 Subject: [PATCH] Fix dev/core#4550 - Crash when saving repeating event --- CRM/Core/Form/RecurringEntity.php | 12 +++++++----- CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 181f7cc140..6390726a75 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -349,6 +349,7 @@ class CRM_Core_Form_RecurringEntity { CRM_Core_BAO_ActionSchedule::deleteRecord($params); unset($params['id']); } + $dbParams['name'] = 'repeat_' . $params['used_for'] . '_' . $params['entity_id']; $actionScheduleObj = CRM_Core_BAO_ActionSchedule::writeRecord($dbParams); //exclude dates @@ -392,7 +393,7 @@ class CRM_Core_Form_RecurringEntity { } } - //Set type for API + // FIXME: This is the worst way possible to convert a table name to an api entity name $apiEntityType = explode("_", $type); if (!empty($apiEntityType[1])) { $apiType = $apiEntityType[1]; @@ -403,10 +404,11 @@ class CRM_Core_Form_RecurringEntity { if (!empty(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func']) && !empty(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class']) ) { - $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], [$params['entity_id']]); - if (!empty($preDeleteResult)) { - call_user_func([CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult]); - } + // FIXME: This calls `CRM_Event_Form_ManageEvent_Repeat::checkRegistrationForEvents` + // which then sets the static variable `CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted` + // which is then accessed below and used to delete events with no registrations. + // I can't think of a worse way to pass a variable back from a function. + call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], [$params['entity_id']]); } //Ready to execute delete on entities if it has delete function set if (!empty(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func']) && diff --git a/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl index c8fcbac9b7..325ab4c919 100644 --- a/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl @@ -1,7 +1,7 @@ {* file to handle db changes in 5.66.alpha1 during upgrade *} {* Ensure action_schedule.name has a unique value *} -UPDATE `civicrm_action_schedule` SET name = CONCAT('reminder_', id) WHERE name IS NULL OR name = ''; +UPDATE `civicrm_action_schedule` SET name = COALESCE(CONCAT('repeat_', used_for, '_', entity_value), CONCAT('schedule_', id)) WHERE name IS NULL OR name = ''; UPDATE `civicrm_action_schedule` a1, `civicrm_action_schedule` a2 SET a2.name = CONCAT(a2.name, '_', a2.id) WHERE a2.name = a1.name AND a2.id > a1.id; -- 2.25.1