From: Jon goldberg Date: Tue, 28 Apr 2015 22:59:19 +0000 (-0600) Subject: CRM-13283 - Basic severity-based hush is working X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=27042a9ec36177b6fddcd70d45c3726237ee5c43;p=civicrm-core.git CRM-13283 - Basic severity-based hush is working --- diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index 0d33f20782..00383282fa 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -207,14 +207,56 @@ class CRM_Utils_Check { CRM_Utils_Hook::check($messages); - //TODO - if ($showHushed) { - $messages[] = new CRM_Utils_Check_Message('ShowHushed', '

SHOWING HUSHED [NOT]

', 'Show Hushed', \Psr\Log\LogLevel::INFO); + if (!$showHushed) { + foreach ($messages as $key => $message) { + $hush = self::checkHushSnooze($message); + if ($hush) { + unset($messages[$key]); + } + } } uasort($messages, array(__CLASS__, 'severitySort')); +CRM_Core_Error::debug('messages', $messages); return $messages; } + /** + * Evaluate if a system check should be hushed/snoozed. + * + * @return bool + * TRUE means hush/snooze, FALSE means display. + */ + public function checkHushSnooze($message) { + // My pseudocode: + // If current_date < statusPreference->date, unset the $message. + // CRM_Core_Error::debug('message', $message); + $statusPreferenceParams = array( + 'name' => $message->getName(), + 'domain_id' => CRM_Core_Config::domainID(), + ); + // Check if there's a StatusPreference matching this name/domain. + $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams); + if ($statusPreference['id']) { + // If so, compare severity to StatusPreference->severity. + $spid = $statusPreference['id']; + $severity = self::severityMap($message->getSeverity()); + if ($severity <= $statusPreference['values'][$spid]['ignore_severity']) { + CRM_Core_Error::debug('snooze', 'possible snooze/hush!'); + // A hush or a snooze has been set. Find out which. + if ($statusPreference['values'][$spid]['hush_until']) { + // Snooze. + CRM_Core_Error::debug('snoozepath', 'snooze'); + $today = new DateTime(); + } + else { + // Hush. + CRM_Core_Error::debug('hushpath', 'hush'); + return TRUE; + } + } + } + return FALSE; + } }