From 5d4bf2ff6bd7dee41954aa867e080a6c595e6e28 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Sep 2014 01:03:18 +0100 Subject: [PATCH] Check participant before deleting events --- CRM/Core/Form/RecurringEntity.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index d57e35497b..04096d2a41 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -263,6 +263,27 @@ class CRM_Core_Form_RecurringEntity { //Delete relations if any from recurring entity tables before inserting new relations for this entity id if($params['parent_event_id']){ + $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($params['parent_event_id'], 'civicrm_event', FALSE); + $implodeRelatedEntities = implode(',', array_map(function($entity){ + return $entity['id']; + }, $getRelatedEntities)); + //Check if participants exists for events + if($implodeRelatedEntities){ + $query = "SELECT event_id, COUNT(*) as count + FROM civicrm_participant + WHERE event_id IN ({$implodeRelatedEntities}) + GROUP BY event_id"; + $dao = CRM_Core_DAO::executeQuery($query); + $participantDetails = array(); + while($dao->fetch()) { + $participantDetails[$dao->event_id] = $dao->count; + } + } + foreach ($getRelatedEntities as $key => $value) { + if(!CRM_Utils_Array::value($value['id'], $participantDetails)){ + CRM_Event_BAO_Event::del($value['id']); + } + } CRM_Core_BAO_RecurringEntity::delEntityRelations($params['parent_event_id'], 'civicrm_event'); } -- 2.25.1