Comment fixes
[civicrm-core.git] / CRM / Utils / Check.php
index 406e242a4c08404ba7ec2e6817e24c660b111ff6..ed441b13ba5edf7c786f486b9e61d78575b65f44 100644 (file)
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id: $
- *
  */
 class CRM_Utils_Check {
-  const
-    // How often to run checks and notify admins about issues.
-    CHECK_TIMER = 86400;
+  // How often to run checks and notify admins about issues.
+  const CHECK_TIMER = 86400;
 
   /**
    * We only need one instance of this object, so we use the
@@ -84,6 +81,9 @@ class CRM_Utils_Check {
         $statusMessages = array();
         $statusType = 'alert';
         foreach ($messages as $message) {
+          if (!$message->isVisible()) {
+            continue;
+          }
           if ($filter === TRUE || $message->getSeverity() >= 3) {
             $statusType = $message->getSeverity() >= 4 ? 'error' : $statusType;
             $statusMessage = $message->getMessage();
@@ -94,10 +94,10 @@ class CRM_Utils_Check {
         if (count($statusMessages)) {
           if (count($statusMessages) > 1) {
             $statusTitle = ts('Multiple Alerts');
-            $statusMessage = '<ul><li>' . implode('</li><li>', $statusMessages) . '</li></ul>';
+            $statusMessage = ts('Please check your <a href="%1">status page</a> for a full list and further details.', array(1 => CRM_Utils_System::url('civicrm/a/#/status'))) . '<ul><li>' . implode('</li><li>', $statusMessages) . '</li></ul>';
           }
 
-          // TODO: add link to status page
+          // @todo add link to status page
           CRM_Core_Session::setStatus($statusMessage, $statusTitle, $statusType);
         }
       }
@@ -111,7 +111,7 @@ class CRM_Utils_Check {
    * @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) {
@@ -171,20 +171,20 @@ class CRM_Utils_Check {
   }
 
   /**
-   * Run some sanity checks.
+   * Run all system checks.
+   *
+   * This functon is wrapped by the System.check api.
    *
-   * This could become a hook so that CiviCRM can run both built-in
-   * configuration & sanity checks, and modules/extensions can add
-   * their own checks.
+   * Calls hook_civicrm_check() for extensions to add or modify messages.
+   * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_check
    *
-   * 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
+   *   Array of CRM_Utils_Check_Message objects
    */
-  public function checkAll($showHushed = FALSE) {
+  public static function checkAll($max = FALSE) {
     $checks = array();
     $checks[] = new CRM_Utils_Check_Security();
     $checks[] = new CRM_Utils_Check_Env();
@@ -207,26 +207,39 @@ class CRM_Utils_Check {
 
     CRM_Utils_Hook::check($messages);
 
-    if (!$showHushed) {
-      foreach ($messages as $key => $message) {
-        $hush = self::checkHushSnooze($message);
-        if ($hush) {
-          unset($messages[$key]);
-        }
-      }
+    foreach ($messages as $key => $message) {
+      $hush = self::checkHushSnooze($message);
+      $messages[$key]->setVisible(!$hush);
     }
     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;
   }
 
   /**
    * Evaluate if a system check should be hushed/snoozed.
    *
+   * @param CRM_Utils_Check_Message $message
+   *   The message to evaluate.
+   *
    * @return bool
    *   TRUE means hush/snooze, FALSE means display.
+   * @throws \CiviCRM_API3_Exception
    */
-  public function checkHushSnooze($message) {
+  public static function checkHushSnooze($message) {
     $statusPreferenceParams = array(
       'name' => $message->getName(),
       'domain_id' => CRM_Core_Config::domainID(),