Remove bad use of PHP assert, removed in PHP 8.0
authorBradley Taylor <hello@brad-taylor.co.uk>
Sat, 19 Mar 2022 11:47:49 +0000 (11:47 +0000)
committerBradley Taylor <hello@brad-taylor.co.uk>
Tue, 22 Mar 2022 21:53:27 +0000 (21:53 +0000)
CRM/Case/Form/Activity/LinkCases.php

index 980a87e9560ff787d3c5651f92221e799a5ea9e2..a524c5be8db4604bca40015132dd651c108ce495 100644 (file)
@@ -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;