Comment fixes
[civicrm-core.git] / CRM / Utils / Check.php
index 4b8267fde9d5c99f78abfa931cfc5cb42f7ae1ba..ed441b13ba5edf7c786f486b9e61d78575b65f44 100644 (file)
@@ -32,7 +32,7 @@
  */
 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
@@ -81,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();
@@ -91,7 +94,7 @@ 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
@@ -108,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) {
@@ -168,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();
@@ -204,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(),