From: Coleman Watts Date: Fri, 11 Dec 2015 13:15:35 +0000 (-0500) Subject: Make assertValid do what it says it does X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c385020443c6a9d4128d0344670bbcfef951adaf;p=civicrm-core.git Make assertValid do what it says it does --- 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)); } }