From a0fdfb650b109cbcee828370d5a9207a0463f782 Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Fri, 30 Nov 2018 16:17:42 +0530 Subject: [PATCH] dev/core#563: Duplicate Case manager role --- CRM/Contact/Page/AJAX.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 8ee4f29d439a..253a0018d055 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -247,13 +247,22 @@ public static function relationship() { // Loop through multiple case clients foreach ($clientList as $i => $sourceContactID) { try { - $result = civicrm_api3('relationship', 'create', array( + $params = [ 'case_id' => $caseID, 'relationship_type_id' => $relTypeId, "contact_id_$a" => $relContactID, "contact_id_$b" => $sourceContactID, + 'sequential' => TRUE, + ]; + // first check if there is any existing relationship present with same parameters. + // If yes then update the relationship by setting active and start date to current time + $relationship = civicrm_api3('Relationship', 'get', $params)['values']; + $params = array_merge(CRM_Utils_Array::value(0, $relationship, $params), [ 'start_date' => 'now', - )); + 'is_active' => TRUE, + 'end_date' => '', + ]); + $result = civicrm_api3('relationship', 'create', $params); } catch (CiviCRM_API3_Exception $e) { $ret['is_error'] = 1;