3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * This api exposes functionality for interacting with the logging functionality.
15 * @package CiviCRM_APIv3
19 * Revert a log change.
21 * @param array $params
25 * @throws \API_Exception
26 * @throws \Civi\API\Exception\UnauthorizedException
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);
34 return civicrm_api3_create_success(1);
40 * @param array $params
42 * @throws \API_Exception
43 * @throws \Civi\API\Exception\UnauthorizedException
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,
51 $params['log_date'] = [
52 'title' => 'Logging Timestamp',
53 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
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'),
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'),
72 * @param array $params
76 * @throws \API_Exception
77 * @throws \Civi\API\Exception\UnauthorizedException
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));
90 * @param array $params
92 * @throws \API_Exception
93 * @throws \Civi\API\Exception\UnauthorizedException
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,
101 $params['log_date'] = [
102 'title' => 'Logging Timestamp',
103 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
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'),
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'),