CRM-12726 : applied patch and did some modifications
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 30 May 2013 12:38:56 +0000 (18:08 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 30 May 2013 12:38:56 +0000 (18:08 +0530)
CRM/Contact/BAO/Contact.php

index 40e746088dd7007833c3b6c6c16c192042945cb1..3ed2b24605a695c65f0ec580e6910437afcd3012 100644 (file)
@@ -772,19 +772,31 @@ WHERE     civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
       $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 {