From f5aae98062cd243df5dde14abab02747321860ff Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 19 Jul 2022 20:38:10 -0700 Subject: [PATCH 1/2] Status Check - Report the overall status (accurately) Overview -------- The page-footer includes a summary message about the system status (eg "System Status: Ok" or "System Status: Error"). The footer has inaccurately summarized the status. Before ------ Suppose you have 5 "Error" messages and 1 "OK" message. It will summarize as "System Status: Ok". (It emphasizes the *least severe* status-message.) Code is more complex. After ------ Suppose you have 5 "Error" messages and 1 "OK" message. It will summarize as "System Status: Error". (It emphasizes the *most severe* status-message.) Code is less complex. Comments -------- The overall value is determined in `CRM_Utils_Check::checkAll()`. Heretofore, `checkAll()` sorted the messages by severity and then emphasized the *first* visible message. The problem is that the sort-order has flip-flopped, so "first" means different things: * In v4.7, the messages were descending. So "first" was "most severe". * In v5.39 (11d593edde82e7de962ec9056cfebe87975fb499), the order was ascending. So "first" was "least severe". (It appears accidental.) * In v5.45 (728c1cc31d0d323f74f7b980a1e183fb499d4e9e), the order flipped back to descending, but *only* for the Angular (`civicrm/a/#/status`) -- not the footer. IMHO, the flip-floppiness means that callers cannot rely on the order returned by `checkAll()` -- they should instead do a higher-level sort (as in v5.45's 728c1cc31d0d323f74f7b980a1e183fb499d4e9e). The `uasort()` within `checkAll()` is therefore redundant. We might as well skip it -- and simplify the logic. --- CRM/Utils/Check.php | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index 0c124a71c239..dd542d808bbf 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -116,23 +116,6 @@ public function showPeriodicAlerts() { } } - /** - * Sort messages based upon severity - * - * @param CRM_Utils_Check_Message $a - * @param CRM_Utils_Check_Message $b - * @return int - */ - public static function severitySort($a, $b) { - $aSeverity = $a->getLevel(); - $bSeverity = $b->getLevel(); - if ($aSeverity == $bSeverity) { - return strcmp($a->getName(), $b->getName()); - } - // The Message constructor guarantees that these will always be integers. - return ($aSeverity <=> $bSeverity); - } - /** * Get the integer value (useful for thresholds) of the severity. * @@ -201,15 +184,11 @@ public function assertValid($messages = NULL, $threshold = \Psr\Log\LogLevel::ER public static function checkAll($max = FALSE) { $messages = self::checkStatus(); - uasort($messages, [__CLASS__, 'severitySort']); - $maxSeverity = 1; foreach ($messages as $message) { - if (!$message->isVisible()) { - continue; + if ($message->isVisible()) { + $maxSeverity = max(1, $message->getLevel()); } - $maxSeverity = max(1, $message->getLevel()); - break; } Civi::cache('checks')->set('systemStatusCheckResult', $maxSeverity); From 2bea08e242ee38b74edb35c89cdbbe0e547ce609 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 20 Jul 2022 14:01:19 -0700 Subject: [PATCH 2/2] Update CRM/Utils/Check.php Co-authored-by: demeritcowboy --- CRM/Utils/Check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index dd542d808bbf..c53912830e29 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -187,7 +187,7 @@ public static function checkAll($max = FALSE) { $maxSeverity = 1; foreach ($messages as $message) { if ($message->isVisible()) { - $maxSeverity = max(1, $message->getLevel()); + $maxSeverity = max($maxSeverity, $message->getLevel()); } }