Set default using spec for activity_date_time
[civicrm-core.git] / api / v3 / Logging.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * This api exposes functionality for interacting with the logging functionality.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18 /**
19 * Revert a log change.
20 *
21 * @param array $params
22 *
23 * @return array
24 * API Success Array
25 * @throws \API_Exception
26 * @throws \Civi\API\Exception\UnauthorizedException
27 */
28 function civicrm_api3_logging_revert($params) {
29 $schema = new CRM_Logging_Schema();
30 $reverter = new CRM_Logging_Reverter($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params));
31 $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact();
32 $reverter->calculateDiffsFromLogConnAndDate($tables);
33 $reverter->revert();
34 return civicrm_api3_create_success(1);
35 }
36
37 /**
38 * Get a log change.
39 *
40 * @param array $params
41 *
42 * @throws \API_Exception
43 * @throws \Civi\API\Exception\UnauthorizedException
44 */
45 function _civicrm_api3_logging_revert_spec(&$params) {
46 $params['log_conn_id'] = [
47 'title' => 'Logging Connection ID',
48 'type' => CRM_Utils_Type::T_STRING,
49 'api.required' => TRUE,
50 ];
51 $params['log_date'] = [
52 'title' => 'Logging Timestamp',
53 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
54 ];
55 $params['interval'] = [
56 'title' => ts('Interval (required if date is included)'),
57 'type' => CRM_Utils_Type::T_STRING,
58 'api.default' => '10 SECOND',
59 'description' => ts('Used when log_date is passed in'),
60 ];
61
62 $params['tables'] = [
63 'title' => ts('Tables to revert'),
64 'type' => CRM_Utils_Type::T_STRING,
65 'description' => ts('Tables to revert, if not set all contact-referring entities will be reverted'),
66 ];
67 }
68
69 /**
70 * Get a log change.
71 *
72 * @param array $params
73 *
74 * @return array
75 * API Success Array
76 * @throws \API_Exception
77 * @throws \Civi\API\Exception\UnauthorizedException
78 */
79 function civicrm_api3_logging_get($params) {
80 $schema = new CRM_Logging_Schema();
81 $interval = (empty($params['log_date'])) ? NULL : $params['interval'];
82 $differ = new CRM_Logging_Differ($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params), $interval);
83 $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact();
84 return civicrm_api3_create_success($differ->getAllChangesForConnection($tables));
85 }
86
87 /**
88 * Get a log change.
89 *
90 * @param array $params
91 *
92 * @throws \API_Exception
93 * @throws \Civi\API\Exception\UnauthorizedException
94 */
95 function _civicrm_api3_logging_get_spec(&$params) {
96 $params['log_conn_id'] = [
97 'title' => 'Logging Connection ID',
98 'type' => CRM_Utils_Type::T_STRING,
99 'api.required' => TRUE,
100 ];
101 $params['log_date'] = [
102 'title' => 'Logging Timestamp',
103 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
104 ];
105 $params['interval'] = [
106 'title' => ts('Interval (required if date is included)'),
107 'type' => CRM_Utils_Type::T_STRING,
108 'api.default' => '10 SECOND',
109 'description' => ts('Used when log_date is passed in'),
110 ];
111 $params['tables'] = [
112 'title' => ts('Tables to query'),
113 'type' => CRM_Utils_Type::T_STRING,
114 'description' => ts('Tables to query, if not set all contact-referring entities will be queried'),
115 ];
116 }