Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
39de6fd5 | 5 | | CiviCRM version 4.6 | |
6a488035 | 6 | +--------------------------------------------------------------------+ |
731a0992 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | * | |
731a0992 | 35 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
36 | * @version $Id: Domain.php 30171 2010-10-14 09:11:27Z mover $ |
37 | * | |
38 | */ | |
39 | ||
40 | /** | |
41 | * Flush all system caches | |
42 | * | |
cf470720 TO |
43 | * @param array $params |
44 | * Input parameters. | |
6a488035 TO |
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 true if success, else false | |
49 | * @static void | |
50 | * @access public | |
51 | * @example SystemFlush.php | |
52 | * | |
53 | */ | |
54 | function civicrm_api3_system_flush($params) { | |
55 | CRM_Core_Invoke::rebuildMenuAndCaches( | |
56 | CRM_Utils_Array::value('triggers', $params, FALSE), | |
57 | CRM_Utils_Array::value('session', $params, FALSE) | |
58 | ); | |
59 | return civicrm_api3_create_success(); | |
60 | } | |
61 | ||
11e09c59 | 62 | /** |
6a488035 TO |
63 | * Adjust Metadata for Flush action |
64 | * | |
65 | * The metadata is used for setting defaults, documentation & validation | |
cf470720 TO |
66 | * @param array $params |
67 | * Array or parameters determined by getfields. | |
6a488035 TO |
68 | */ |
69 | function _civicrm_api3_system_flush_spec(&$params){ | |
70 | $params['triggers'] = array('title' => 'rebuild triggers (boolean)'); | |
71 | $params['session'] = array('title' => 'refresh sessions (boolean)'); | |
9ef501da | 72 | } |
6a488035 | 73 | |
9ef501da TO |
74 | /** |
75 | * System.Check API specification (optional) | |
76 | * This is used for documentation and validation. | |
77 | * | |
cf470720 TO |
78 | * @param array $spec |
79 | * Description of fields supported by this API call. | |
9ef501da TO |
80 | * @return void |
81 | * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
82 | */ | |
83 | function _civicrm_api3_system_check_spec(&$spec) { | |
84 | // $spec['magicword']['api.required'] = 1; | |
232624b1 | 85 | } |
9ef501da TO |
86 | |
87 | /** | |
88 | * System.Check API | |
89 | * | |
90 | * @param array $params | |
91 | * @return array API result descriptor; return items are alert codes/messages | |
92 | * @see civicrm_api3_create_success | |
93 | * @see civicrm_api3_create_error | |
94 | * @throws API_Exception | |
95 | */ | |
96 | function civicrm_api3_system_check($params) { | |
97 | $returnValues = array(); | |
1248c859 | 98 | foreach (CRM_Utils_Check::singleton()->checkAll() as $message) { |
9ef501da TO |
99 | $returnValues[] = $message->toArray(); |
100 | } | |
101 | ||
102 | // Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL) | |
103 | return civicrm_api3_create_success($returnValues, $params, 'System', 'Check'); | |
e2bef985 | 104 | } |
105 | ||
106 | /** | |
c490a46a | 107 | * @param array $params |
e2bef985 | 108 | * |
109 | * @return array | |
110 | */ | |
111 | function civicrm_api3_system_log($params) { | |
112 | $log = new CRM_Utils_SystemLogger(); | |
113 | // this part means fields with separate db storage are accepted as params which kind of seems more intuitive to me | |
114 | // 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? | |
22e263ad | 115 | if (!isset($params['context'])) { |
e2bef985 | 116 | $params['context'] = array(); |
117 | } | |
118 | $specialFields = array('contact_id', 'hostname'); | |
22e263ad TO |
119 | foreach ($specialFields as $specialField) { |
120 | if (isset($params[$specialField]) && !isset($params['context'])) { | |
e2bef985 | 121 | $params['context'][$specialField] = $params[$specialField]; |
122 | } | |
123 | } | |
124 | $returnValues = $log->log($params['level'], $params['message'], $params['context']); | |
125 | return civicrm_api3_create_success($returnValues, $params, 'System', 'Log'); | |
126 | } | |
127 | ||
128 | /** | |
129 | * Metadata for log function | |
c490a46a | 130 | * @param array $params |
e2bef985 | 131 | */ |
4f8ccea0 | 132 | function _civicrm_api3_system_log_spec(&$params) { |
e2bef985 | 133 | $params['level'] = array( |
134 | 'title' => 'Log Level', | |
135 | 'description' => 'Log level as described in PSR3 (info, debug, warning etc)', | |
136 | 'type' => CRM_Utils_Type::T_STRING, | |
137 | 'api.required' => TRUE, | |
138 | ); | |
139 | $params['message'] = array( | |
140 | 'title' => 'Log Message', | |
141 | 'description' => 'Standardised message string, you can also ', | |
142 | 'type' => CRM_Utils_Type::T_STRING, | |
143 | 'api.required' => TRUE, | |
144 | ); | |
145 | $params['context'] = array( | |
146 | 'title' => 'Log Context', | |
147 | 'description' => 'An array of additional data to store.', | |
148 | 'type' => CRM_Utils_Type::T_LONGTEXT, | |
149 | 'api.default' => array(), | |
150 | ); | |
151 | $params['contact_id'] = array( | |
152 | 'title' => 'Log Contact ID', | |
153 | 'description' => 'Optional ID of relevant contact', | |
154 | 'type' => CRM_Utils_Type::T_INT, | |
155 | ); | |
156 | $params['hostname'] = array( | |
157 | 'title' => 'Log Hostname', | |
158 | 'description' => 'Optional name of host', | |
159 | 'type' => CRM_Utils_Type::T_STRING, | |
160 | ); | |
161 | } | |
42bf9336 | 162 | |
91f1889e TO |
163 | /** |
164 | * System.Get API | |
165 | * | |
166 | * @param arary $params | |
167 | */ | |
168 | function civicrm_api3_system_get($params) { | |
169 | $returnValues = array( | |
170 | array( | |
171 | 'version' => CRM_Utils_System::version(), | |
172 | 'uf' => CIVICRM_UF, | |
173 | ), | |
174 | ); | |
175 | return civicrm_api3_create_success($returnValues, $params, 'System', 'get'); | |
176 | } |