From: unknown Date: Mon, 8 Sep 2014 00:03:18 +0000 (+0100) Subject: Check participant before deleting events X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5d4bf2ff6bd7dee41954aa867e080a6c595e6e28;p=civicrm-core.git Check participant before deleting events --- 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'); }