if (CRM_Core_Config::isUpgradeMode()) {
return;
}
- $statusSeverity = 0;
- $statusMessage = ts('System status OK');
+ // check date of last cache and compare to today's date
+ $systemCheckDate = Civi::cache()->get('systemCheckDate');
+ if ($systemCheckDate > strtotime("one day ago")) {
+ $statusSeverity = Civi::cache()->get('systemCheckSeverity');
+ }
+ // calls helper function in CRM_Utils_Check
+ if (empty($statusSeverity)) {
+ $statusSeverity = CRM_Utils_Check::checkAll(TRUE);
+ }
+ switch ($statusSeverity) {
+ case 7:
+ $statusMessage = ts('System Status: Emergency');
+ break;
+
+ case 6:
+ $statusMessage = ts('System Status: Alert');
+ break;
+
+ case 5:
+ $statusMessage = ts('System Status: Critical');
+ break;
+
+ case 4:
+ $statusMessage = ts('System Status: Error');
+ break;
+
+ case 3:
+ $statusMessage = ts('System Status: Warning');
+ break;
+
+ case 2:
+ $statusMessage = ts('System Status: Notice');
+ break;
+
+ default:
+ $statusMessage = ts('System Status: Ok');
+ }
// TODO: get status from CRM_Utils_Check, if cached
$template->assign('footer_status_severity', $statusSeverity);
$template->assign('footer_status_message', $statusMessage);
*/
class CRM_Utils_Check {
// How often to run checks and notify admins about issues.
- const CHECK_TIMER = 86400;
+ const CHECK_TIMER = 86400;
/**
* We only need one instance of this object, so we use the
* @param CRM_Utils_Check_Message $b
* @return int
*/
- public function severitySort($a, $b) {
+ public static function severitySort($a, $b) {
$aSeverity = $a->getSeverity();
$bSeverity = $b->getSeverity();
if ($aSeverity == $bSeverity) {
* We might even expose the results of these checks on the Wordpress
* plugin status page or the Drupal admin/reports/status path.
*
+ * @param bool $max
+ * Whether to return just the maximum non-hushed severity
+ *
* @return array
* Array of messages
* @link https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements
*/
- public function checkAll() {
+ public static function checkAll($max = FALSE) {
$checks = array();
$checks[] = new CRM_Utils_Check_Security();
$checks[] = new CRM_Utils_Check_Env();
}
uasort($messages, array(__CLASS__, 'severitySort'));
- return $messages;
+ $maxSeverity = 1;
+ foreach ($messages as $message) {
+ if (!$message->isVisible()) {
+ continue;
+ }
+ $maxSeverity = max(1, $message->getLevel());
+ break;
+ }
+
+ Civi::cache()->set('systemCheckSeverity', $maxSeverity);
+ $timestamp = time();
+ Civi::cache()->set('systemCheckDate', $timestamp);
+
+ return ($max) ? $maxSeverity : $messages;
}
/**
* @return bool
* TRUE means hush/snooze, FALSE means display.
*/
- public function checkHushSnooze($message) {
+ public static function checkHushSnooze($message) {
$statusPreferenceParams = array(
'name' => $message->getName(),
'domain_id' => CRM_Core_Config::domainID(),
<div class="crm-footer" id="civicrm-footer">
{crmVersion assign=version}
{ts 1=$version}Powered by CiviCRM %1.{/ts}
- {if !empty($statusSeverity)}
- <span class="status{if $statusSeverity gt 2} crm-error{else} crm-ok{/if}">
+ {if $footer_status_severity}
+ <span class="status{if $footer_status_severity gt 3} crm-error{elseif $footer_status_severity gt 2} crm-warning{else} crm-ok{/if}">
<a href="{crmURL p='civicrm/a/#/status'}">{$footer_status_message}</a>
</span>
{/if}