Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-10-14-11-16-10
authorkurund <kurund@civicrm.org>
Tue, 14 Oct 2014 05:52:18 +0000 (11:22 +0530)
committerkurund <kurund@civicrm.org>
Tue, 14 Oct 2014 05:52:18 +0000 (11:22 +0530)
Conflicts:
api/v3/System.php
tests/phpunit/api/v3/SystemTest.php

1  2 
api/v3/System.php
tests/phpunit/api/v3/SystemTest.php

index 79c66f264578aa539992a62d01dbf1bbe2e35cda,a75c404d70eea661e2edf12a806d1bee3039b698..6dcf12b9de7c6b0c21f182c44cddb512ad75498d
@@@ -100,59 -100,17 +100,75 @@@ function civicrm_api3_system_check($par
    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');
+ }
++
index 3d6b5a7243d7e20db9418c3859dd8b238cdad1ec,999b223a42f773a300317bebefa39f78f2bfe00d..b1ce57d14930fc9496aa39c68a5e577d932bfdce
@@@ -1,10 -1,10 +1,9 @@@
  <?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 {
  
@@@ -68,7 -68,7 +41,8 @@@
     *  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']);
+   }
  }