From 894d9dbc5e2adb6b2f51f32f93188e99a5cff42c Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Wed, 16 Nov 2022 15:54:43 +0000 Subject: [PATCH 1/2] Code cleanup caseaddrole --- CRM/CivirulesActions/Case/AddRole.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CRM/CivirulesActions/Case/AddRole.php b/CRM/CivirulesActions/Case/AddRole.php index 93236c82..bbb395b1 100644 --- a/CRM/CivirulesActions/Case/AddRole.php +++ b/CRM/CivirulesActions/Case/AddRole.php @@ -8,7 +8,6 @@ class CRM_CivirulesActions_Case_AddRole extends CRM_Civirules_Action { * Process the action * * @param CRM_Civirules_TriggerData_TriggerData $triggerData - * @access public */ public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData) { $case = $triggerData->getEntityData("Case"); @@ -76,7 +75,6 @@ class CRM_CivirulesActions_Case_AddRole extends CRM_Civirules_Action { * e.g. 'Older than 65' * * @return string - * @access public */ public function userFriendlyConditionParams() { $params = $this->getActionParameters(); @@ -85,7 +83,6 @@ class CRM_CivirulesActions_Case_AddRole extends CRM_Civirules_Action { return E::ts('Add %2 to the case with role <em>%1</em>', array(1 => $roles[$params['role']], 2 =>$display_name)); } - /** * Validates whether this action works with the selected trigger. * @@ -106,7 +103,7 @@ class CRM_CivirulesActions_Case_AddRole extends CRM_Civirules_Action { */ public static function getCaseRoles() { $relationshipTypesApi = civicrm_api3('RelationshipType', 'get', ['options' => ['limit' => 0]]); - $caseRoles = array(); + $caseRoles = []; foreach($relationshipTypesApi['values'] as $relType) { $caseRoles[$relType['id']] = $relType['label_a_b']; } -- GitLab From 94892adb700ed3ceb0e3f7cb96f2a4d72f2be41e Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Wed, 16 Nov 2022 15:55:01 +0000 Subject: [PATCH 2/2] Don't crash if contact ID does not exist (eg. was deleted) --- CRM/CivirulesActions/Case/AddRole.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CRM/CivirulesActions/Case/AddRole.php b/CRM/CivirulesActions/Case/AddRole.php index bbb395b1..64a68628 100644 --- a/CRM/CivirulesActions/Case/AddRole.php +++ b/CRM/CivirulesActions/Case/AddRole.php @@ -79,8 +79,11 @@ class CRM_CivirulesActions_Case_AddRole extends CRM_Civirules_Action { public function userFriendlyConditionParams() { $params = $this->getActionParameters(); $roles = self::getCaseRoles(); - $display_name = civicrm_api3('Contact', 'getvalue', ['id' => $params['cid'], 'return' => 'display_name']); - return E::ts('Add %2 to the case with role <em>%1</em>', array(1 => $roles[$params['role']], 2 =>$display_name)); + $contactDisplayName = \Civi\Api4\Contact::get(FALSE) + ->addWhere('id', '=', $params['cid']) + ->execute() + ->first()['display_name'] ?? ''; + return E::ts('Add %2 to the case with role <em>%1</em>', [1 => $roles[$params['role']], 2 => $contactDisplayName]); } /** -- GitLab