Commit | Line | Data |
---|---|---|
93afbc3a | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
93afbc3a | 5 | | | |
a30c801b TO |
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 | | |
93afbc3a | 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 | |
7c31ae57 | 24 | * API Success Array |
93afbc3a | 25 | * @throws \API_Exception |
26 | * @throws \Civi\API\Exception\UnauthorizedException | |
27 | */ | |
28 | function civicrm_api3_logging_revert($params) { | |
29 | $schema = new CRM_Logging_Schema(); | |
99008b08 | 30 | $reverter = new CRM_Logging_Reverter($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params)); |
f16074c9 | 31 | $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact(); |
32 | $reverter->calculateDiffsFromLogConnAndDate($tables); | |
93afbc3a | 33 | $reverter->revert(); |
34 | return civicrm_api3_create_success(1); | |
35 | } | |
29444295 | 36 | |
353918bc | 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) { | |
cf8f0fff | 46 | $params['log_conn_id'] = [ |
353918bc | 47 | 'title' => 'Logging Connection ID', |
48 | 'type' => CRM_Utils_Type::T_STRING, | |
49 | 'api.required' => TRUE, | |
cf8f0fff CW |
50 | ]; |
51 | $params['log_date'] = [ | |
353918bc | 52 | 'title' => 'Logging Timestamp', |
53 | 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, | |
cf8f0fff CW |
54 | ]; |
55 | $params['interval'] = [ | |
353918bc | 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'), | |
cf8f0fff | 60 | ]; |
f16074c9 | 61 | |
cf8f0fff | 62 | $params['tables'] = [ |
f16074c9 | 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'), | |
cf8f0fff | 66 | ]; |
353918bc | 67 | } |
68 | ||
29444295 | 69 | /** |
70 | * Get a log change. | |
71 | * | |
72 | * @param array $params | |
73 | * | |
74 | * @return array | |
7c31ae57 | 75 | * API Success Array |
29444295 | 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); | |
f16074c9 | 83 | $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact(); |
84 | return civicrm_api3_create_success($differ->getAllChangesForConnection($tables)); | |
29444295 | 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) { | |
cf8f0fff | 96 | $params['log_conn_id'] = [ |
29444295 | 97 | 'title' => 'Logging Connection ID', |
98 | 'type' => CRM_Utils_Type::T_STRING, | |
99 | 'api.required' => TRUE, | |
cf8f0fff CW |
100 | ]; |
101 | $params['log_date'] = [ | |
29444295 | 102 | 'title' => 'Logging Timestamp', |
103 | 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, | |
cf8f0fff CW |
104 | ]; |
105 | $params['interval'] = [ | |
29444295 | 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'), | |
cf8f0fff CW |
110 | ]; |
111 | $params['tables'] = [ | |
f16074c9 | 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'), | |
cf8f0fff | 115 | ]; |
29444295 | 116 | } |