5da438e636e34473cde4a93c72f476e5102292b7
[civicrm-core.git] / api / v3 / System.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 * File for the CiviCRM APIv3 domain functions
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Domain
34 *
35 * @copyright CiviCRM LLC (c) 2004-2014
36 * @version $Id: Domain.php 30171 2010-10-14 09:11:27Z mover $
37 *
38 */
39
40 /**
41 * Flush all system caches
42 *
43 * @param array $params
44 * Input parameters.
45 * - triggers: bool, whether to drop/create SQL triggers; default: FALSE
46 * - session: bool, whether to reset the CiviCRM session data; defaul: FALSE
47 *
48 * @return boolean
49 * true if success, else false
50 * @static void
51 * @access public
52 * @example SystemFlush.php
53 *
54 */
55 function civicrm_api3_system_flush($params) {
56 CRM_Core_Invoke::rebuildMenuAndCaches(
57 CRM_Utils_Array::value('triggers', $params, FALSE),
58 CRM_Utils_Array::value('session', $params, FALSE)
59 );
60 return civicrm_api3_create_success();
61 }
62
63 /**
64 * Adjust Metadata for Flush action
65 *
66 * The metadata is used for setting defaults, documentation & validation
67 * @param array $params
68 * Array or parameters determined by getfields.
69 */
70 function _civicrm_api3_system_flush_spec(&$params) {
71 $params['triggers'] = array('title' => 'rebuild triggers (boolean)');
72 $params['session'] = array('title' => 'refresh sessions (boolean)');
73 }
74
75 /**
76 * System.Check API specification (optional)
77 * This is used for documentation and validation.
78 *
79 * @param array $spec
80 * Description of fields supported by this API call.
81 * @return void
82 * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
83 */
84 function _civicrm_api3_system_check_spec(&$spec) {
85 // $spec['magicword']['api.required'] = 1;
86 }
87
88 /**
89 * System.Check API
90 *
91 * @param array $params
92 * @return array
93 * API result descriptor; return items are alert codes/messages
94 * @see civicrm_api3_create_success
95 * @see civicrm_api3_create_error
96 * @throws API_Exception
97 */
98 function civicrm_api3_system_check($params) {
99 $returnValues = array();
100 foreach (CRM_Utils_Check::singleton()->checkAll() as $message) {
101 $returnValues[] = $message->toArray();
102 }
103
104 // Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL)
105 return civicrm_api3_create_success($returnValues, $params, 'System', 'Check');
106 }
107
108 /**
109 * @param array $params
110 *
111 * @return array
112 */
113 function civicrm_api3_system_log($params) {
114 $log = new CRM_Utils_SystemLogger();
115 // this part means fields with separate db storage are accepted as params which kind of seems more intuitive to me
116 // 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?
117 if (!isset($params['context'])) {
118 $params['context'] = array();
119 }
120 $specialFields = array('contact_id', 'hostname');
121 foreach ($specialFields as $specialField) {
122 if (isset($params[$specialField]) && !isset($params['context'])) {
123 $params['context'][$specialField] = $params[$specialField];
124 }
125 }
126 $returnValues = $log->log($params['level'], $params['message'], $params['context']);
127 return civicrm_api3_create_success($returnValues, $params, 'System', 'Log');
128 }
129
130 /**
131 * Metadata for log function
132 * @param array $params
133 */
134 function _civicrm_api3_system_log_spec(&$params) {
135 $params['level'] = array(
136 'title' => 'Log Level',
137 'description' => 'Log level as described in PSR3 (info, debug, warning etc)',
138 'type' => CRM_Utils_Type::T_STRING,
139 'api.required' => TRUE,
140 );
141 $params['message'] = array(
142 'title' => 'Log Message',
143 'description' => 'Standardised message string, you can also ',
144 'type' => CRM_Utils_Type::T_STRING,
145 'api.required' => TRUE,
146 );
147 $params['context'] = array(
148 'title' => 'Log Context',
149 'description' => 'An array of additional data to store.',
150 'type' => CRM_Utils_Type::T_LONGTEXT,
151 'api.default' => array(),
152 );
153 $params['contact_id'] = array(
154 'title' => 'Log Contact ID',
155 'description' => 'Optional ID of relevant contact',
156 'type' => CRM_Utils_Type::T_INT,
157 );
158 $params['hostname'] = array(
159 'title' => 'Log Hostname',
160 'description' => 'Optional name of host',
161 'type' => CRM_Utils_Type::T_STRING,
162 );
163 }
164
165 /**
166 * System.Get API
167 *
168 * @param arary $params
169 */
170 function civicrm_api3_system_get($params) {
171 $returnValues = array(
172 array(
173 'version' => CRM_Utils_System::version(),
174 'uf' => CIVICRM_UF,
175 ),
176 );
177 return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
178 }