From db4b2428e87cb42fd87d6609977c3e6a844e56ec Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Mon, 6 Jul 2020 16:33:54 +0200 Subject: [PATCH] update to pr 16559 --- CRM/Case/XMLProcessor/Process.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CRM/Case/XMLProcessor/Process.php b/CRM/Case/XMLProcessor/Process.php index 6bffb852dd..d010a47c68 100644 --- a/CRM/Case/XMLProcessor/Process.php +++ b/CRM/Case/XMLProcessor/Process.php @@ -459,7 +459,7 @@ AND a.is_deleted = 0 ]; } - $activityParams['assignee_contact_id'] = $this->getDefaultAssigneeForActivity($activityParams, $activityTypeXML); + $activityParams['assignee_contact_id'] = $this->getDefaultAssigneeForActivity($activityParams, $activityTypeXML, $params['caseID']); //parsing date to default preference format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time']); @@ -559,10 +559,11 @@ AND a.is_deleted = 0 * * @param array $activityParams * @param object $activityTypeXML + * @param int $caseId * * @return int|null the ID of the default assignee contact or null if none. */ - protected function getDefaultAssigneeForActivity($activityParams, $activityTypeXML) { + protected function getDefaultAssigneeForActivity($activityParams, $activityTypeXML, $caseId) { if (!isset($activityTypeXML->default_assignee_type)) { return NULL; } @@ -571,7 +572,7 @@ AND a.is_deleted = 0 switch ($activityTypeXML->default_assignee_type) { case $defaultAssigneeOptionsValues['BY_RELATIONSHIP']: - return $this->getDefaultAssigneeByRelationship($activityParams, $activityTypeXML); + return $this->getDefaultAssigneeByRelationship($activityParams, $activityTypeXML, $caseId); break; case $defaultAssigneeOptionsValues['SPECIFIC_CONTACT']: @@ -616,10 +617,11 @@ AND a.is_deleted = 0 * * @param array $activityParams * @param object $activityTypeXML + * @param int $caseId * * @return int|null the ID of the default assignee contact or null if none. */ - protected function getDefaultAssigneeByRelationship($activityParams, $activityTypeXML) { + protected function getDefaultAssigneeByRelationship($activityParams, $activityTypeXML, $caseId) { $isDefaultRelationshipDefined = isset($activityTypeXML->default_assignee_relationship) && preg_match('/\d+_[ab]_[ab]/', $activityTypeXML->default_assignee_relationship); @@ -636,6 +638,8 @@ AND a.is_deleted = 0 'relationship_type_id' => $relTypeId, "contact_id_$b" => $targetContactId, 'is_active' => 1, + 'case_id' => $caseId, + 'options' => ['limit' => 1], ]; if ($this->isBidirectionalRelationshipType($relTypeId)) { @@ -644,6 +648,10 @@ AND a.is_deleted = 0 } $relationships = civicrm_api3('Relationship', 'get', $params); + if (empty($relationships['count'])) { + $params['case_id'] = ['IS NULL' => 1]; + $relationships = civicrm_api3('Relationship', 'get', $params); + } if ($relationships['count']) { $relationship = CRM_Utils_Array::first($relationships['values']); -- 2.25.1