From 8d99ab37809b297aaa0b5bb928c43ed64a368b50 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 25 Mar 2014 22:44:39 -0400 Subject: [PATCH] Fix testContactCreateCurrentEmployer --- api/v3/Contact.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/v3/Contact.php b/api/v3/Contact.php index a60425ffb8..1f7c0ba260 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -332,10 +332,11 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE } } - //check for organisations with same name + // The BAO no longer supports the legacy param "current_employer" so here is a shim for api backward-compatability if (!empty($params['current_employer'])) { - $organizationParams = array(); - $organizationParams['organization_name'] = $params['current_employer']; + $organizationParams = array( + 'organization_name' => $params['current_employer'], + ); $dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization'); @@ -351,6 +352,17 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE if (empty($params['employer_id']) && (count($dupeIds) > 1)) { throw new API_Exception('Found more than one Organisation with same Name.'); } + + if ($dupeIds) { + $params['employer_id'] = $dupeIds[0]; + } + else { + $result = civicrm_api3('contact', 'create', array( + 'organization_name' => $params['current_employer'], + 'contact_type' => 'Organization' + )); + $params['employer_id'] = $result['id']; + } } return NULL; -- 2.25.1