/**
* Execute "checkAll".
*
- * @param array|NULL $messages list of CRM_Utils_Check_Message; or NULL if the default list should be fetched
+ * @param array|NULL $messages
+ * List of CRM_Utils_Check_Message; or NULL if the default list should be fetched.
+ * @param array|string|callable $filter
+ * Restrict messages using a callback filter.
+ * By default, only show warnings and errors.
+ * Set TRUE to show all messages.
*/
- public function showPeriodicAlerts($messages = NULL) {
+ public function showPeriodicAlerts($messages = NULL, $filter = array(__CLASS__, 'isImportantAlert')) {
if (CRM_Core_Permission::check('administer CiviCRM')
&& CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityAlert', NULL, TRUE)
) {
$messages = $this->checkAll();
}
foreach ($messages as $message) {
- CRM_Core_Session::setStatus($message->getMessage(), $message->getTitle());
+ if ($filter === TRUE || call_user_func($filter, $message)) {
+ CRM_Core_Session::setStatus($message->getMessage(), $message->getTitle());
+ }
}
}
}
}
+ /**
+ * Determine if a message is important enough to harass the administrator about.
+ *
+ * @param CRM_Utils_Check_Message $message
+ * @return bool
+ */
+ protected static function isImportantAlert($message) {
+ return in_array($message->getLevel(), array(
+ \Psr\Log\LogLevel::WARNING,
+ \Psr\Log\LogLevel::ALERT,
+ \Psr\Log\LogLevel::CRITICAL,
+ \Psr\Log\LogLevel::EMERGENCY,
+ ));
+ }
+
/**
* Throw an exception if any of the checks fail.
*
*/
private $title;
+ /**
+ * @var string
+ * @see Psr\Log\LogLevel
+ */
+ private $level;
+
/**
* @param string $name
- * @param $message
- * @param $title
+ * Symbolic name for the check.
+ * @param string $message
+ * Printable message (short or long).
+ * @param string $title
+ * Printable message (short).
+ * @param string $level
+ * The severity of the message. Use PSR-3 log levels.
+ *
+ * @see Psr\Log\LogLevel
*/
- public function __construct($name, $message, $title) {
+ public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING) {
$this->name = $name;
$this->message = $message;
$this->title = $title;
+ $this->level = $level;
}
/**
return $this->title;
}
+ /**
+ * @return string
+ * @see Psr\Log\LogLevel
+ */
+ public function getLevel() {
+ return $this->level;
+ }
+
/**
* @return array
*/
'name' => $this->name,
'message' => $this->message,
'title' => $this->title,
+ 'level' => $this->level,
);
}