System.check api cleanup
authorColeman Watts <coleman@civicrm.org>
Tue, 17 Nov 2015 01:39:07 +0000 (20:39 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 17 Nov 2015 02:26:49 +0000 (21:26 -0500)
CRM/Utils/Check.php
api/v3/System.php

index 25f7e4e2cb729534757804d06d4214fbf01b9936..a7db9408ad0ee80a4c0a1346ddd6955f5d7b2855 100644 (file)
@@ -34,6 +34,21 @@ class CRM_Utils_Check {
   // How often to run checks and notify admins about issues.
   const CHECK_TIMER = 86400;
 
+  /**
+   * @var array
+   * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
+   */
+  public static $severityMap = array(
+    \Psr\Log\LogLevel::DEBUG,
+    \Psr\Log\LogLevel::INFO,
+    \Psr\Log\LogLevel::NOTICE,
+    \Psr\Log\LogLevel::WARNING,
+    \Psr\Log\LogLevel::ERROR,
+    \Psr\Log\LogLevel::CRITICAL,
+    \Psr\Log\LogLevel::ALERT,
+    \Psr\Log\LogLevel::EMERGENCY,
+  );
+
   /**
    * We only need one instance of this object, so we use the
    * singleton pattern and cache the instance in this variable
@@ -136,18 +151,7 @@ class CRM_Utils_Check {
       $severity = strtolower($severity);
     }
 
-    // See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
-    $levels = array(
-      \Psr\Log\LogLevel::EMERGENCY => 7,
-      \Psr\Log\LogLevel::ALERT => 6,
-      \Psr\Log\LogLevel::CRITICAL => 5,
-      \Psr\Log\LogLevel::ERROR => 4,
-      \Psr\Log\LogLevel::WARNING => 3,
-      \Psr\Log\LogLevel::NOTICE => 2,
-      \Psr\Log\LogLevel::INFO => 1,
-      \Psr\Log\LogLevel::DEBUG => 0,
-    );
-    return ($reverse) ? array_search($severity, $levels) : $levels[$severity];
+    return ($reverse) ? self::$severityMap[$severity] : array_search($severity, self::$severityMap);
   }
 
   /**
index 21fc343ea4607ec32e4fe4f2c6e2f5890928a36d..56ec8897dd74cb840937f8ab447e8e2239f059b6 100644 (file)
@@ -83,11 +83,47 @@ function _civicrm_api3_system_flush_spec(&$params) {
  * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
  */
 function _civicrm_api3_system_check_spec(&$spec) {
-  // $spec['magicword']['api.required'] = 1;
+  $spec['id'] = array(
+    'title' => 'ID',
+    'description' => 'Not a real identifier - do not use',
+    'type' => CRM_Utils_Type::T_INT,
+  );
+  $spec['name'] = array(
+    'title' => 'Name',
+    'description' => 'Unique identifier',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
+  $spec['title'] = array(
+    'title' => 'Title',
+    'description' => 'Short title text',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
+  $spec['message'] = array(
+    'title' => 'Message',
+    'description' => 'Long description html',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
+  $spec['help'] = array(
+    'title' => 'Help',
+    'description' => 'Optional extra help (html string)',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
+  $spec['severity'] = array(
+    'title' => 'Severity',
+    'description' => 'Integer representation of Psr\Log\LogLevel',
+    'type' => CRM_Utils_Type::T_INT,
+    'options' => CRM_Utils_Check::$severityMap,
+  );
   $spec['is_visible'] = array(
     'title' => 'is visible',
+    'description' => '0 if message has been hidden by the user',
     'type' => CRM_Utils_Type::T_BOOLEAN,
   );
+  $spec['hidden_until'] = array(
+    'title' => 'Hidden_until',
+    'description' => 'When will hidden message be visible again?',
+    'type' => CRM_Utils_Type::T_DATE,
+  );
 }
 
 /**
@@ -104,16 +140,17 @@ function _civicrm_api3_system_check_spec(&$spec) {
 function civicrm_api3_system_check($params) {
   // array(array('name'=> $, 'severity'=>$, ...))
   $id = 1;
-  $returnValues = array();
+  $returnValues = $fields = array();
+  _civicrm_api3_system_check_spec($fields);
 
   // array(CRM_Utils_Check_Message)
-  $messages = CRM_Utils_Check::singleton()->checkAll();
+  $messages = CRM_Utils_Check::checkAll();
 
   foreach ($messages as $msg) {
     $returnValues[] = $msg->toArray() + array('id' => $id++);
   }
 
-  return _civicrm_api3_basic_array_get('systemCheck', $params, $returnValues, "id", array('id', 'name', 'message', 'title', 'severity', 'is_visible'));
+  return _civicrm_api3_basic_array_get('systemCheck', $params, $returnValues, "id", array_keys($fields));
 }
 
 /**