$logDAO->entity_table = 'civicrm_contact';
$logDAO->entity_id = $id;
$logDAO->delete();
-
+
// delete contact participants CRM-12155
CRM_Event_BAO_Participant::deleteContactParticipant($id);
// delete contact contributions CRM-12155
CRM_Contribute_BAO_Contribution::deleteContactContribution($id);
-
+
// do activity cleanup, CRM-5604
CRM_Activity_BAO_Activity::cleanupActivity($id);
// delete all notes related to contact
CRM_Core_BAO_Note::cleanContactNotes($id);
+ // delete cases related to contact
+ $contactCases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($id);
+ if (!empty($contactCases)) {
+ foreach($contactCases as $caseId){
+ //check if case is associate with other contact or not.
+ $caseContactId = CRM_Case_BAO_Case::getCaseClients($caseId);
+ if(count($caseContactId) <= 1){
+ CRM_Case_BAO_Case::deleteCase($caseId);
+ }
+ }
+ }
+
$contact->delete();
}
else {