From b121501728bf4a055af8d13f662c5f47bc19c109 Mon Sep 17 00:00:00 2001 From: Bradley Taylor Date: Sat, 19 Mar 2022 11:47:49 +0000 Subject: [PATCH] Remove bad use of PHP assert, removed in PHP 8.0 --- CRM/Case/Form/Activity/LinkCases.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CRM/Case/Form/Activity/LinkCases.php b/CRM/Case/Form/Activity/LinkCases.php index 980a87e956..a524c5be8d 100644 --- a/CRM/Case/Form/Activity/LinkCases.php +++ b/CRM/Case/Form/Activity/LinkCases.php @@ -99,15 +99,22 @@ class CRM_Case_Form_Activity_LinkCases { $errors = []; $linkCaseId = $values['link_to_case_id'] ?? NULL; - assert('is_numeric($linkCaseId)'); + + if (!CRM_Utils_Rule::positiveInteger($linkCaseId) || $linkCaseId == 0) { + // We can't just return $errors because when the page reloads the + // entityref widget throws an error before the page can display the error. + // It seems ok with other invalid values, just not 0, but both are equally invalid. + CRM_Core_Error::statusBounce(ts('The linked case ID is invalid.')); + } + if ($linkCaseId == CRM_Utils_Array::first($form->_caseId)) { - $errors['link_to_case'] = ts('Please select some other case to link.'); + $errors['link_to_case_id'] = ts('Please select some other case to link.'); } // do check for existing related cases. $relatedCases = $form->get('relatedCases'); if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) { - $errors['link_to_case'] = ts('Selected case is already linked.'); + $errors['link_to_case_id'] = ts('Selected case is already linked.'); } return empty($errors) ? TRUE : $errors; -- 2.25.1