From c385020443c6a9d4128d0344670bbcfef951adaf Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 11 Dec 2015 08:15:35 -0500 Subject: [PATCH] Make assertValid do what it says it does --- CRM/Utils/Check.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index ea6c3c9b12..f2a40b7657 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -162,20 +162,26 @@ class CRM_Utils_Check { /** * Throw an exception if any of the checks fail. * - * @param array|NULL $messages list of CRM_Utils_Check_Message; or NULL if the default list should be fetched + * @param array|NULL $messages + * [CRM_Utils_Check_Message] + * @param string $threshold * - * @throws Exception + * @throws \CRM_Core_Exception + * @throws \Exception */ - public function assertValid($messages = NULL) { + public function assertValid($messages = NULL, $threshold = \Psr\Log\LogLevel::ERROR) { if ($messages === NULL) { $messages = $this->checkAll(); } - if (!empty($messages)) { - $messagesAsArray = array(); - foreach ($messages as $message) { - $messagesAsArray[] = $message->toArray(); + $minLevel = self::severityMap($threshold); + $errors = array(); + foreach ($messages as $message) { + if ($message->getLevel() >= $minLevel) { + $errors[] = $message->toArray(); } - throw new Exception('There are configuration problems with this installation: ' . print_r($messagesAsArray, TRUE)); + } + if ($errors) { + throw new Exception("System $threshold: " . print_r($errors, TRUE)); } } -- 2.25.1