From f55dd13550f42618410435fb97820cc1de9285b7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 18 Nov 2015 11:21:00 -0500 Subject: [PATCH] CRM-13823 - Fix caching of system status --- CRM/Core/Invoke.php | 20 ++++++-------------- CRM/Utils/Check.php | 8 ++------ settings/Core.setting.php | 13 +++++++++++++ templates/CRM/common/footer.tpl | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CRM/Core/Invoke.php b/CRM/Core/Invoke.php index 7c38eb6eb3..972850a04f 100644 --- a/CRM/Core/Invoke.php +++ b/CRM/Core/Invoke.php @@ -344,24 +344,17 @@ class CRM_Core_Invoke { } /** - * Show status in the footer + * Show status in the footer (admin only) * * @param CRM_Core_Smarty $template */ public static function statusCheck($template) { - if (CRM_Core_Config::isUpgradeMode()) { + if (CRM_Core_Config::isUpgradeMode() || !CRM_Core_Permission::check('administer CiviCRM')) { return; } - // 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) { + // always use cached results - they will be refreshed by the session timer + $status = Civi::settings()->get('systemStatusCheckResult'); + switch ($status) { case 7: $statusMessage = ts('System Status: Emergency'); break; @@ -389,8 +382,7 @@ class CRM_Core_Invoke { 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_severity', $status); $template->assign('footer_status_message', $statusMessage); } diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index 0f7db75aea..783989b0f4 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -87,9 +87,7 @@ class CRM_Utils_Check { * Set TRUE to show all messages. */ public function showPeriodicAlerts($messages = NULL, $filter = array(__CLASS__, 'severityMap')) { - if (CRM_Core_Permission::check('administer CiviCRM') - && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityAlert', NULL, TRUE) - ) { + if (CRM_Core_Permission::check('administer CiviCRM')) { $session = CRM_Core_Session::singleton(); if ($session->timer('check_' . __CLASS__, self::CHECK_TIMER)) { @@ -237,9 +235,7 @@ class CRM_Utils_Check { break; } - Civi::cache()->set('systemCheckSeverity', $maxSeverity); - $timestamp = time(); - Civi::cache()->set('systemCheckDate', $timestamp); + Civi::settings()->set('systemStatusCheckResult', $maxSeverity); return ($max) ? $maxSeverity : $messages; } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 1d483c4c28..d7d817c13b 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -800,4 +800,17 @@ return array( 'description' => NULL, 'help_text' => NULL, ), + 'systemStatusCheckResult' => array( + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'systemStatusCheckResult', + 'type' => 'Integer', + 'default' => 0, + 'add' => '4.7', + 'title' => NULL, + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => NULL, + 'help_text' => NULL, + ), ); diff --git a/templates/CRM/common/footer.tpl b/templates/CRM/common/footer.tpl index 242e573555..b1ce4f5895 100644 --- a/templates/CRM/common/footer.tpl +++ b/templates/CRM/common/footer.tpl @@ -32,7 +32,7 @@