From e5e4a5b211ffda34b45ad9f8c7580367df1a6346 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 16 Nov 2015 20:39:07 -0500 Subject: [PATCH] System.check api cleanup --- CRM/Utils/Check.php | 28 ++++++++++++++++------------ api/v3/System.php | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index 25f7e4e2cb..a7db9408ad 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -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); } /** diff --git a/api/v3/System.php b/api/v3/System.php index 21fc343ea4..56ec8897dd 100644 --- a/api/v3/System.php +++ b/api/v3/System.php @@ -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)); } /** -- 2.25.1