CRM-20345 - Don't be tripped up by deleted contacts or inactive relationships
authorColeman Watts <coleman@civicrm.org>
Thu, 30 Mar 2017 00:29:24 +0000 (20:29 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 Mar 2017 00:29:24 +0000 (20:29 -0400)
CRM/Case/BAO/Case.php
api/v3/Case.php

index 14946c4c1334aa21217a1363f692c95661df8657..78943a5254a191cb4ef6059d6b5191bb3a4829c9 100644 (file)
@@ -1235,7 +1235,7 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
       LEFT JOIN civicrm_email ce
         ON ce.contact_id = cc.id
         AND ce.is_primary= 1
-      WHERE cr.case_id =  %1';
+      WHERE cr.case_id =  %1 AND cr.is_active AND cc.is_deleted <> 1';
 
     $params = array(1 => array($caseID, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $params);
index 849e32228de300cbc82ad5f571d083bd7a5ad61b..ddf3aead95c2667d3aac4ca701e01e8363f6c8ea 100644 (file)
@@ -269,7 +269,7 @@ function civicrm_api3_case_get($params, $sql = NULL) {
     // Add necessary joins to the first case client
     if ($contactSort) {
       $sql->join('ccc', 'LEFT JOIN (SELECT * FROM civicrm_case_contact WHERE id IN (SELECT MIN(id) FROM civicrm_case_contact GROUP BY case_id)) AS ccc ON ccc.case_id = a.id');
-      $sql->join('case_contact', 'LEFT JOIN civicrm_contact AS case_contact ON ccc.contact_id = case_contact.id');
+      $sql->join('case_contact', 'LEFT JOIN civicrm_contact AS case_contact ON ccc.contact_id = case_contact.id AND case_contact.is_deleted <> 1');
     }
   }