From da4d891093df9c00257dbee4699f5bc77813e612 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sun, 23 Jul 2017 11:17:48 +0100 Subject: [PATCH 01/11] Allow case API create to work with custom data --- CRM/Case/BAO/Case.php | 4 +- api/v3/Case.php | 152 +++++++++++++++++++++++++++--------------- 2 files changed, 103 insertions(+), 53 deletions(-) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index df23c5fa1cda..2490024ad6c7 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -75,7 +75,9 @@ public static function enabled() { public static function add(&$params) { $caseDAO = new CRM_Case_DAO_Case(); $caseDAO->copyValues($params); - return $caseDAO->save(); + $result = $caseDAO->save(); + $caseDAO->find(TRUE); // Get other case values (required by XML processor), this adds to $result array + return $result; } /** diff --git a/api/v3/Case.php b/api/v3/Case.php index df6332a3eb25..1554ec99edbc 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -60,37 +60,67 @@ * api result array */ function civicrm_api3_case_create($params) { + // Process params + $values = array(); + _civicrm_api3_custom_format_params($params, $values, 'Case'); + $params = array_merge($params, $values); - if (!empty($params['id'])) { - return civicrm_api3_case_update($params); - } - - civicrm_api3_verify_mandatory($params, NULL, array( - 'contact_id', - 'subject', - array('case_type', 'case_type_id')) - ); _civicrm_api3_case_format_params($params); - // If format_params didn't find what it was looking for, return error - if (empty($params['case_type_id'])) { - throw new API_Exception('Invalid case_type. No such case type exists.'); - } - if (empty($params['case_type'])) { - throw new API_Exception('Invalid case_type_id. No such case type exists.'); + if (empty($params['id'])) { + // Creating a new case, so make sure we have the necessary parameters + civicrm_api3_verify_mandatory($params, NULL, [ + 'contact_id', + 'subject', + ['case_type', 'case_type_id'] + ] + ); } + else { + // Update an existing case + // FIXME: Some of this logic should move to the BAO object? + // FIXME: Should we check if case with ID actually exists? + if (!isset($params['case_id']) && isset($params['id'])) { + $params['case_id'] = $params['id']; + } - // Fixme: can we safely pass raw params to the BAO? - $newParams = array( - 'case_type_id' => $params['case_type_id'], - 'creator_id' => $params['creator_id'], - 'status_id' => $params['status_id'], - 'start_date' => $params['start_date'], - 'end_date' => CRM_Utils_Array::value('end_date', $params), - 'subject' => $params['subject'], - ); + // return error if modifying creator id + if (array_key_exists('creator_id', $params)) { + throw new API_Exception(ts('You cannot update creator id')); + } + + $mCaseId = $origContactIds = array(); + + // 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]; + } + + if (count($origContactIds) > 1) { + // check valid orig contact id + if (!empty($params['orig_contact_id']) && !in_array($params['orig_contact_id'], $origContactIds)) { + throw new API_Exception('Invalid case contact id (orig_contact_id)'); + } + elseif (empty($params['orig_contact_id'])) { + throw new API_Exception('Case is linked with more than one contact id. Provide the required params orig_contact_id to be replaced'); + } + $origContactId = $params['orig_contact_id']; + } - $caseBAO = CRM_Case_BAO_Case::create($newParams); + // check for same contact id for edit Client + if (!empty($params['contact_id']) && !in_array($params['contact_id'], $origContactIds)) { + $mCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $params['case_id'], $origContactId, NULL, TRUE); + } + + // If we merged cases then update the merged case + if (!empty($mCaseId[0])) { + $params['id'] = $mCaseId[0]; + } + } + + // Create/update the case + $caseBAO = CRM_Case_BAO_Case::create($params); if (!$caseBAO) { throw new API_Exception('Case not created. Please check input params.'); @@ -101,31 +131,46 @@ function civicrm_api3_case_create($params) { CRM_Case_BAO_CaseContact::create($contactParams); } + if (!isset($params['id'])) { + // Creating a new case + _civicrm_api3_case_create_xmlProcessor($params, $caseBAO); + } + + // return case + $values = array(); + _civicrm_api3_object_to_array($caseBAO, $values[$caseBAO->id]); + + // Add custom data + if (isset($params['custom'])) { + _civicrm_api3_custom_data_get($values[$caseBAO->id],TRUE,'case',$caseBAO->id); + } + + return civicrm_api3_create_success($values, $params, 'Case', 'create', $caseBAO); +} + +function _civicrm_api3_case_create_xmlProcessor($params, $caseBAO) { + // Format params for xmlProcessor + if (isset($caseBAO->id)) { $params['id'] = $caseBAO->id; } + // Initialize XML processor with $params $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array( - 'clientID' => $params['contact_id'], - 'creatorID' => $params['creator_id'], + 'clientID' => CRM_Utils_Array::value('contact_id',$params), + 'creatorID' => CRM_Utils_Array::value('creator_id',$params), 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', - 'caseID' => $caseBAO->id, - 'subject' => $params['subject'], - 'location' => CRM_Utils_Array::value('location', $params), - 'activity_date_time' => $params['start_date'], - 'duration' => CRM_Utils_Array::value('duration', $params), - 'medium_id' => CRM_Utils_Array::value('medium_id', $params), - 'details' => CRM_Utils_Array::value('details', $params), + 'caseID' => CRM_Utils_Array::value('id',$params), + 'subject' => CRM_Utils_Array::value('subject',$params), + 'location' => CRM_Utils_Array::value('location',$params), + 'activity_date_time' => CRM_Utils_Array::value('start_date',$params), + 'duration' => CRM_Utils_Array::value('duration',$params), + 'medium_id' => CRM_Utils_Array::value('medium_id',$params), + 'details' => CRM_Utils_Array::value('details',$params), 'custom' => array(), ); // Do it! :-D $xmlProcessor->run($params['case_type'], $xmlProcessorParams); - - // return case - $values = array(); - _civicrm_api3_object_to_array($caseBAO, $values[$caseBAO->id]); - - return civicrm_api3_create_success($values, $params, 'Case', 'create', $caseBAO); } /** @@ -645,23 +690,26 @@ function _civicrm_api3_case_read(&$cases, $options) { * @param array $params */ function _civicrm_api3_case_format_params(&$params) { - // figure out case type id from case type and vice-versa - $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); - if (empty($params['case_type_id'])) { - $params['case_type_id'] = array_search($params['case_type'], $caseTypes); - - // DEPRECATED: lookup by label for backward compatibility - if (!$params['case_type_id']) { - $caseTypeLabels = CRM_Case_PseudoConstant::caseType('title', FALSE); - $params['case_type_id'] = array_search($params['case_type'], $caseTypeLabels); + if (!empty($params['case_type_id']) || !empty($params['case_type'])) { + // figure out case type id from case type and vice-versa + $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); + if (empty($params['case_type_id'])) { + $params['case_type_id'] = array_search($params['case_type'], $caseTypes); + + // DEPRECATED: lookup by label for backward compatibility + if (!$params['case_type_id']) { + $caseTypeLabels = CRM_Case_PseudoConstant::caseType('title', FALSE); + $params['case_type_id'] = array_search($params['case_type'], $caseTypeLabels); + $params['case_type'] = $caseTypes[$params['case_type_id']]; + } + } + elseif (empty($params['case_type'])) { $params['case_type'] = $caseTypes[$params['case_type_id']]; } } - elseif (empty($params['case_type'])) { - $params['case_type'] = $caseTypes[$params['case_type_id']]; - } } + /** * It actually works a lot better to use the CaseContact api instead of the Case api * for entityRef fields so we can perform the necessary joins, From 2a3c0d28459b6a5c1c94b1fd21a327028232dabd Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 11:20:54 +0100 Subject: [PATCH 02/11] Refactor based on comments from @davialexandre --- api/v3/Case.php | 93 +++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index 1554ec99edbc..b999933bb5e6 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -60,20 +60,15 @@ * api result array */ function civicrm_api3_case_create($params) { - // Process params - $values = array(); - _civicrm_api3_custom_format_params($params, $values, 'Case'); - $params = array_merge($params, $values); - _civicrm_api3_case_format_params($params); if (empty($params['id'])) { // Creating a new case, so make sure we have the necessary parameters - civicrm_api3_verify_mandatory($params, NULL, [ + civicrm_api3_verify_mandatory($params, NULL, array( 'contact_id', 'subject', - ['case_type', 'case_type_id'] - ] + array('case_type', 'case_type_id') + ) ); } else { @@ -84,38 +79,40 @@ function civicrm_api3_case_create($params) { $params['case_id'] = $params['id']; } - // return error if modifying creator id if (array_key_exists('creator_id', $params)) { throw new API_Exception(ts('You cannot update creator id')); } - $mCaseId = $origContactIds = array(); + $mergedCaseId = $origContactIds = array(); // 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]; } + // FIXME: Refactor as separate method to get contactId if (count($origContactIds) > 1) { // check valid orig contact id + if (empty($params['orig_contact_id'])) { + throw new API_Exception('Case is linked with more than one contact id. Provide the required params orig_contact_id to be replaced'); + } if (!empty($params['orig_contact_id']) && !in_array($params['orig_contact_id'], $origContactIds)) { throw new API_Exception('Invalid case contact id (orig_contact_id)'); } - elseif (empty($params['orig_contact_id'])) { - throw new API_Exception('Case is linked with more than one contact id. Provide the required params orig_contact_id to be replaced'); - } $origContactId = $params['orig_contact_id']; } // check for same contact id for edit Client if (!empty($params['contact_id']) && !in_array($params['contact_id'], $origContactIds)) { - $mCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $params['case_id'], $origContactId, NULL, TRUE); + $mergedCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $params['case_id'], $origContactId, NULL, TRUE); } // If we merged cases then update the merged case - if (!empty($mCaseId[0])) { - $params['id'] = $mCaseId[0]; + if (!empty($mergedCaseId[0])) { + $params['id'] = $mergedCaseId[0]; } } @@ -132,7 +129,8 @@ function civicrm_api3_case_create($params) { } if (!isset($params['id'])) { - // Creating a new case + // As the API was not passed an id we have created a new case. + // Only run the xmlProcessor for new cases to get all configuration for the new case. _civicrm_api3_case_create_xmlProcessor($params, $caseBAO); } @@ -142,12 +140,18 @@ function civicrm_api3_case_create($params) { // Add custom data if (isset($params['custom'])) { - _civicrm_api3_custom_data_get($values[$caseBAO->id],TRUE,'case',$caseBAO->id); + _civicrm_api3_custom_data_get($values[$caseBAO->id], TRUE, 'case', $caseBAO->id); } return civicrm_api3_create_success($values, $params, 'Case', 'create', $caseBAO); } +/** + * When creating a new case, run the xmlProcessor to get all necessary params/configuration + * for the new case, as cases use an xml file to store their configuration. + * @param $params + * @param $caseBAO + */ function _civicrm_api3_case_create_xmlProcessor($params, $caseBAO) { // Format params for xmlProcessor if (isset($caseBAO->id)) { $params['id'] = $caseBAO->id; } @@ -155,17 +159,17 @@ function _civicrm_api3_case_create_xmlProcessor($params, $caseBAO) { // Initialize XML processor with $params $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array( - 'clientID' => CRM_Utils_Array::value('contact_id',$params), - 'creatorID' => CRM_Utils_Array::value('creator_id',$params), + 'clientID' => CRM_Utils_Array::value('contact_id', $params), + 'creatorID' => CRM_Utils_Array::value('creator_id', $params), 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', - 'caseID' => CRM_Utils_Array::value('id',$params), - 'subject' => CRM_Utils_Array::value('subject',$params), - 'location' => CRM_Utils_Array::value('location',$params), - 'activity_date_time' => CRM_Utils_Array::value('start_date',$params), - 'duration' => CRM_Utils_Array::value('duration',$params), - 'medium_id' => CRM_Utils_Array::value('medium_id',$params), - 'details' => CRM_Utils_Array::value('details',$params), + 'caseID' => CRM_Utils_Array::value('id', $params), + 'subject' => CRM_Utils_Array::value('subject', $params), + 'location' => CRM_Utils_Array::value('location', $params), + 'activity_date_time' => CRM_Utils_Array::value('start_date', $params), + 'duration' => CRM_Utils_Array::value('duration', $params), + 'medium_id' => CRM_Utils_Array::value('medium_id', $params), + 'details' => CRM_Utils_Array::value('details', $params), 'custom' => array(), ); @@ -690,23 +694,30 @@ function _civicrm_api3_case_read(&$cases, $options) { * @param array $params */ function _civicrm_api3_case_format_params(&$params) { - if (!empty($params['case_type_id']) || !empty($params['case_type'])) { - // figure out case type id from case type and vice-versa - $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); - if (empty($params['case_type_id'])) { - $params['case_type_id'] = array_search($params['case_type'], $caseTypes); - - // DEPRECATED: lookup by label for backward compatibility - if (!$params['case_type_id']) { - $caseTypeLabels = CRM_Case_PseudoConstant::caseType('title', FALSE); - $params['case_type_id'] = array_search($params['case_type'], $caseTypeLabels); - $params['case_type'] = $caseTypes[$params['case_type_id']]; - } - } - elseif (empty($params['case_type'])) { + // Format/include custom params + $values = array(); + _civicrm_api3_custom_format_params($params, $values, 'Case'); + $params = array_merge($params, $values); + + if (empty($params['case_type_id']) && empty($params['case_type'])) { + return; + } + + // figure out case_type_id from case_type and vice-versa + $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); + if (empty($params['case_type_id'])) { + $params['case_type_id'] = array_search($params['case_type'], $caseTypes); + + // DEPRECATED: lookup by label for backward compatibility + if (!$params['case_type_id']) { + $caseTypeLabels = CRM_Case_PseudoConstant::caseType('title', FALSE); + $params['case_type_id'] = array_search($params['case_type'], $caseTypeLabels); $params['case_type'] = $caseTypes[$params['case_type_id']]; } } + elseif (empty($params['case_type'])) { + $params['case_type'] = $caseTypes[$params['case_type_id']]; + } } From 3755d87996214f378fde02c8fea7d68ca6095d98 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 11:24:50 +0100 Subject: [PATCH 03/11] Add deprecated label to case update api function --- api/v3/Case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index b999933bb5e6..3ba5e46c72f3 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -495,7 +495,7 @@ function _civicrm_api3_case_deprecation() { } /** - * Update a specified case. + * @deprecated Update a specified case. Use civicrm_api3_case_create() instead. * * @param array $params * //REQUIRED: From ebf4aeaa73ef71ce353e2fd42cc6583776f3eed3 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 11:31:22 +0100 Subject: [PATCH 04/11] Fix style warnings --- api/v3/Case.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index 3ba5e46c72f3..ec11167b5735 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -154,7 +154,9 @@ function civicrm_api3_case_create($params) { */ function _civicrm_api3_case_create_xmlProcessor($params, $caseBAO) { // Format params for xmlProcessor - if (isset($caseBAO->id)) { $params['id'] = $caseBAO->id; } + if (isset($caseBAO->id)) { + $params['id'] = $caseBAO->id; + } // Initialize XML processor with $params $xmlProcessor = new CRM_Case_XMLProcessor_Process(); @@ -698,7 +700,7 @@ function _civicrm_api3_case_format_params(&$params) { $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Case'); $params = array_merge($params, $values); - + if (empty($params['case_type_id']) && empty($params['case_type'])) { return; } From 18174a47042efcabfe5aba7213448b166af9a931 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 11:34:16 +0100 Subject: [PATCH 05/11] Style warning --- api/v3/Case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index ec11167b5735..b51bfe335daf 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -67,7 +67,7 @@ function civicrm_api3_case_create($params) { civicrm_api3_verify_mandatory($params, NULL, array( 'contact_id', 'subject', - array('case_type', 'case_type_id') + array('case_type', 'case_type_id'), ) ); } From 791a8dc46f14297748195bea584c5d7066980190 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 12:20:41 +0100 Subject: [PATCH 06/11] contact_id is optional when updating case, this change allows existing Case unit tests to pass --- api/v3/Case.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index b51bfe335daf..d923ebd2f63e 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -39,11 +39,13 @@ * @param array $params * * @code - * //REQUIRED: + * //REQUIRED for create: * 'case_type_id' => int OR * 'case_type' => str (provide one or the other) * 'contact_id' => int // case client * 'subject' => str + * //REQUIRED for update: + * 'id' => case Id * * //OPTIONAL * 'medium_id' => int // see civicrm option values for possibilities @@ -123,9 +125,11 @@ function civicrm_api3_case_create($params) { throw new API_Exception('Case not created. Please check input params.'); } - foreach ((array) $params['contact_id'] as $cid) { - $contactParams = array('case_id' => $caseBAO->id, 'contact_id' => $cid); - CRM_Case_BAO_CaseContact::create($contactParams); + if (isset($params['contact_id'])) { + foreach ((array) $params['contact_id'] as $cid) { + $contactParams = array('case_id' => $caseBAO->id, 'contact_id' => $cid); + CRM_Case_BAO_CaseContact::create($contactParams); + } } if (!isset($params['id'])) { From c35f56928076739ad1293edd8165e0248fc3ae86 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 12:33:28 +0100 Subject: [PATCH 07/11] Add unit tests for case create api custom data --- tests/phpunit/api/v3/CaseTest.php | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 6e9845fc0c64..32363b90255d 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -146,6 +146,24 @@ public function testCaseCreate() { $this->assertEquals($result['values'][$id]['subject'], $params['subject']); } + /** + * Test case create with valid parameters and custom data. + */ + public function testCaseCreateCustom() { + $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); + $params = $this->_params; + $params['custom_' . $ids['custom_field_id']] = "custom string"; + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess($this->_entity, 'get', array( + 'return.custom_' . $ids['custom_field_id'] => 1, + 'id' => $result['id'], + )); + $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); + + $this->customFieldDelete($ids['custom_field_id']); + $this->customGroupDelete($ids['custom_group_id']); + } + /** * Test update (create with id) function with valid parameters. */ @@ -168,6 +186,43 @@ public function testCaseUpdate() { $this->assertAPIArrayComparison($result, $case); } + /** + * Test case update with custom data + */ + public function testCaseUpdateCustom() { + $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); + $params = $this->_params; + + // Create a case with custom data + $params['custom_' . $ids['custom_field_id']] = 'custom string'; + $result = $this->callAPISuccess($this->_entity, 'create', $params); + + $caseId = $result['id']; + $result = $this->callAPISuccess($this->_entity, 'get', array( + 'return.custom_' . $ids['custom_field_id'] => 1, + 'version' => 3, + 'id' => $result['id'], + )); + $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); + $fields = $this->callAPISuccess($this->_entity, 'getfields', array('version' => $this->_apiversion)); + $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']])); + + // Update the activity with custom data. + $params = array( + 'id' => $caseId, + 'custom_' . $ids['custom_field_id'] => 'Updated my test data', + 'version' => $this->_apiversion, + ); + $result = $this->callAPISuccess($this->_entity, 'create', $params); + + $result = $this->callAPISuccess($this->_entity, 'get', array( + 'return.custom_' . $ids['custom_field_id'] => 1, + 'version' => 3, + 'id' => $result['id'], + )); + $this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); + } + /** * Test delete function with valid parameters. */ From ef76301b5e82b25f99714d2d82b47f08d50b92d5 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 16:20:08 +0100 Subject: [PATCH 08/11] Don't use ts for exceptions --- api/v3/Case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index d923ebd2f63e..5f9d4733bfb5 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -82,7 +82,7 @@ function civicrm_api3_case_create($params) { } if (array_key_exists('creator_id', $params)) { - throw new API_Exception(ts('You cannot update creator id')); + throw new API_Exception('You cannot update creator id'); } $mergedCaseId = $origContactIds = array(); From 2e50efb54a318870966a5b3eb187062591d5b4fe Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Wed, 9 Aug 2017 09:32:54 +0100 Subject: [PATCH 09/11] We don't need to return custom data on create --- api/v3/Case.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index 5f9d4733bfb5..c8a0f46b87f0 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -142,11 +142,6 @@ function civicrm_api3_case_create($params) { $values = array(); _civicrm_api3_object_to_array($caseBAO, $values[$caseBAO->id]); - // Add custom data - if (isset($params['custom'])) { - _civicrm_api3_custom_data_get($values[$caseBAO->id], TRUE, 'case', $caseBAO->id); - } - return civicrm_api3_create_success($values, $params, 'Case', 'create', $caseBAO); } From f37c1b4760470b1a7080ec4cc3f27626607f6a85 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 10 Aug 2017 21:33:12 +0100 Subject: [PATCH 10/11] Use CRM_Utils_Array:first() for robustness --- CRM/Case/BAO/Case.php | 1 + api/v3/Case.php | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 2490024ad6c7..609c3d3cbab9 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -273,6 +273,7 @@ public static function retrieveContactIdsByCaseId($caseId, $contactID = NULL) { $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 c8a0f46b87f0..b2a2bd9fc081 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) { From ad851b1f3eb9484ef87d9747ac5c6e638799541e Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 10 Aug 2017 21:37:58 +0100 Subject: [PATCH 11/11] Remove blank lines --- api/v3/Case.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/v3/Case.php b/api/v3/Case.php index b2a2bd9fc081..bc263b0944a6 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -91,8 +91,6 @@ function civicrm_api3_case_create($params) { if (!empty($params['contact_id'])) { $origContactIds = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($params['id']); $origContactId = CRM_Utils_Array::first($origContactIds); - - } // FIXME: Refactor as separate method to get contactId