return civicrm_api3_create_success($returnValues, $params, 'System', 'Check');
}
+/**
+ * @param $params
+ *
+ * @return array
+ */
+function civicrm_api3_system_log($params) {
+ $log = new CRM_Utils_SystemLogger();
+ // this part means fields with separate db storage are accepted as params which kind of seems more intuitive to me
+ // because I felt like not doing this required a bunch of explanation in the spec function - but perhaps other won't see it as helpful?
+ if(!isset($params['context'])) {
+ $params['context'] = array();
+ }
+ $specialFields = array('contact_id', 'hostname');
+ foreach($specialFields as $specialField) {
+ if(isset($params[$specialField]) && !isset($params['context'])) {
+ $params['context'][$specialField] = $params[$specialField];
+ }
+ }
+ $returnValues = $log->log($params['level'], $params['message'], $params['context']);
+ return civicrm_api3_create_success($returnValues, $params, 'System', 'Log');
+}
+
+/**
+ * Metadata for log function
+ * @param $params
+ */
+function _civicrm_api3_system_log_spec(&$params) {
+ $params['level'] = array(
+ 'title' => 'Log Level',
+ 'description' => 'Log level as described in PSR3 (info, debug, warning etc)',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'api.required' => TRUE,
+ );
+ $params['message'] = array(
+ 'title' => 'Log Message',
+ 'description' => 'Standardised message string, you can also ',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'api.required' => TRUE,
+ );
+ $params['context'] = array(
+ 'title' => 'Log Context',
+ 'description' => 'An array of additional data to store.',
+ 'type' => CRM_Utils_Type::T_LONGTEXT,
+ 'api.default' => array(),
+ );
+ $params['contact_id'] = array(
+ 'title' => 'Log Contact ID',
+ 'description' => 'Optional ID of relevant contact',
+ 'type' => CRM_Utils_Type::T_INT,
+ );
+ $params['hostname'] = array(
+ 'title' => 'Log Hostname',
+ 'description' => 'Optional name of host',
+ 'type' => CRM_Utils_Type::T_STRING,
+ );
+}
++
+ /**
+ * System.Get API
+ *
+ * @param arary $params
+ */
+ function civicrm_api3_system_get($params) {
+ $returnValues = array(
+ array(
+ 'version' => CRM_Utils_System::version(),
+ 'uf' => CIVICRM_UF,
+ ),
+ );
+ return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
+ }
++
<?php
--
/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.4 |
+| CiviCRM version 4.5 |
+--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2013 |
+| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
+--------------------------------------------------------------------+
*/
--/*
-- +--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
- | CiviCRM version 4.4 |
-- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
- | Copyright CiviCRM LLC (c) 2004-2013 |
-- +--------------------------------------------------------------------+
-- | This file is a part of CiviCRM. |
-- | |
-- | CiviCRM is free software; you can copy, modify, and distribute it |
-- | under the terms of the GNU Affero General Public License |
-- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
-- | |
-- | CiviCRM is distributed in the hope that it will be useful, but |
-- | WITHOUT ANY WARRANTY; without even the implied warranty of |
-- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
-- | See the GNU Affero General Public License for more details. |
-- | |
-- | You should have received a copy of the GNU Affero General Public |
-- | License and the CiviCRM Licensing Exception along |
-- | with this program; if not, contact CiviCRM LLC |
-- | at info[AT]civicrm[DOT]org. If you have questions about the |
-- | GNU Affero General Public License or the licensing of CiviCRM, |
-- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
-- +--------------------------------------------------------------------+
--*/
--
require_once 'CiviTest/CiviUnitTestCase.php';
/**
* Test class for System API - civicrm_system_*
*
-- * @package CiviCRM
++ * @package CiviCRM
*/
class api_v3_SystemTest extends CiviUnitTestCase {
* Constructor
*
* Initialize configuration
-- */ function __construct() {
++ */
++ function __construct() {
parent::__construct();
}
$this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
}
- $result = $this->callAPISuccess('SystemLog', 'getsingle', array('sequential' => 1, 'message' => array('LIKE' => '%Chris%')));
+ /**
+ * Test system log function
+ */
+ function testSystemLog() {
+ $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas'));
- $this->callAPISuccess('system', 'log', array( 'message' => 'We wish you a merry Christmas', 'level' => 'alert'));
- $result = $this->callAPISuccess('SystemLog', 'getsingle', array('sequential' => 1, 'message' => array('LIKE' => '%Chris%')));
++ $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
++ 'sequential' => 1,
++ 'message' => array('LIKE' => '%Chris%')
++ ));
+ $this->assertEquals($result['message'], 'We wish you a merry Christmas');
+ $this->assertEquals($result['level'], 'info');
+ }
+
+ /**
+ * Test system log function
+ */
+ function testSystemLogNoLevel() {
++ $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert'));
++ $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
++ 'sequential' => 1,
++ 'message' => array('LIKE' => '%Chris%')
++ ));
+ $this->assertEquals($result['message'], 'We wish you a merry Christmas');
+ $this->assertEquals($result['level'], 'alert');
+ }
++
+ function testSystemGet() {
+ $result = $this->callAPISuccess('system', 'get', array());
+ $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']);
+ $this->assertEquals('UnitTests', $result['values'][0]['uf']);
+ }
}