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 | * | |
a6c01b45 | 48 | * @return boolean |
72b3a70c | 49 | * true if success, else false |
5f53b1c1 | 50 | * @static |
6a488035 TO |
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 | ||
11e09c59 | 63 | /** |
6a488035 TO |
64 | * Adjust Metadata for Flush action |
65 | * | |
66 | * The metadata is used for setting defaults, documentation & validation | |
cf470720 TO |
67 | * @param array $params |
68 | * Array or parameters determined by getfields. | |
6a488035 | 69 | */ |
9b873358 | 70 | function _civicrm_api3_system_flush_spec(&$params) { |
6a488035 TO |
71 | $params['triggers'] = array('title' => 'rebuild triggers (boolean)'); |
72 | $params['session'] = array('title' => 'refresh sessions (boolean)'); | |
9ef501da | 73 | } |
6a488035 | 74 | |
9ef501da TO |
75 | /** |
76 | * System.Check API specification (optional) | |
77 | * This is used for documentation and validation. | |
78 | * | |
cf470720 TO |
79 | * @param array $spec |
80 | * Description of fields supported by this API call. | |
9ef501da TO |
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; | |
232624b1 | 86 | } |
9ef501da TO |
87 | |
88 | /** | |
89 | * System.Check API | |
90 | * | |
91 | * @param array $params | |
a6c01b45 | 92 | * @return array |
72b3a70c | 93 | * API result descriptor; return items are alert codes/messages |
9ef501da TO |
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(); | |
1248c859 | 100 | foreach (CRM_Utils_Check::singleton()->checkAll() as $message) { |
9ef501da TO |
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'); | |
e2bef985 | 106 | } |
107 | ||
108 | /** | |
c490a46a | 109 | * @param array $params |
e2bef985 | 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? | |
22e263ad | 117 | if (!isset($params['context'])) { |
e2bef985 | 118 | $params['context'] = array(); |
119 | } | |
120 | $specialFields = array('contact_id', 'hostname'); | |
22e263ad TO |
121 | foreach ($specialFields as $specialField) { |
122 | if (isset($params[$specialField]) && !isset($params['context'])) { | |
e2bef985 | 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 | |
c490a46a | 132 | * @param array $params |
e2bef985 | 133 | */ |
4f8ccea0 | 134 | function _civicrm_api3_system_log_spec(&$params) { |
e2bef985 | 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 | } | |
42bf9336 | 164 | |
91f1889e TO |
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 | } |