/**
* 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));
}
}