From: Matthew Wire Date: Thu, 10 Aug 2017 20:33:12 +0000 (+0100) Subject: Use CRM_Utils_Array:first() for robustness X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f37c1b4760470b1a7080ec4cc3f27626607f6a85;p=civicrm-core.git Use CRM_Utils_Array:first() for robustness --- diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 2490024ad6..609c3d3cba 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -273,6 +273,7 @@ WHERE civicrm_case.id = %1"; $caseContact->case_id = $caseId; $caseContact->find(); $contactArray = array(); + // FIXME: Why does this return a 1-based array? $count = 1; while ($caseContact->fetch()) { if ($contactID != $caseContact->contact_id) { diff --git a/api/v3/Case.php b/api/v3/Case.php index c8a0f46b87..b2a2bd9fc0 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -89,10 +89,10 @@ function civicrm_api3_case_create($params) { // get original contact id and creator id of case if (!empty($params['contact_id'])) { - // FIXME: CRM_Case_BAO_Case::retrieveContactIdsByCaseId returns a 1-based array (1 is the first element) - // It should really return a 0-based array for consistency. $origContactIds = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($params['id']); - $origContactId = $origContactIds[1]; + $origContactId = CRM_Utils_Array::first($origContactIds); + + } // FIXME: Refactor as separate method to get contactId @@ -529,7 +529,7 @@ function civicrm_api3_case_update($params) { // get original contact id and creator id of case if (!empty($params['contact_id'])) { $origContactIds = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($params['id']); - $origContactId = $origContactIds[1]; + $origContactId = CRM_Utils_Array::first($origContactIds); } if (count($origContactIds) > 1) {