Fix dev/core#4550 - Crash when saving repeating event
authorcolemanw <coleman@civicrm.org>
Tue, 5 Sep 2023 21:34:15 +0000 (17:34 -0400)
committercolemanw <coleman@civicrm.org>
Tue, 5 Sep 2023 21:34:15 +0000 (17:34 -0400)
CRM/Core/Form/RecurringEntity.php
CRM/Upgrade/Incremental/sql/5.66.alpha1.mysql.tpl

index 181f7cc14077d1012ce19e3c5f1d37e993d5f114..6390726a755f03cb287224ba0f5c831656acdead 100644 (file)
@@ -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']) &&
index c8fcbac9b787b5e2730aeaec51bb9d41cc116202..325ab4c919cee5ddf3257c3c7deed40a55f03acf 100644 (file)
@@ -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;