93afbc3a |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | CiviCRM version 4.7 | |
5 | +--------------------------------------------------------------------+ |
1f4ea726 |
6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
93afbc3a |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | |
9 | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
11 | | under the terms of the GNU Affero General Public License | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
13 | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
17 | | See the GNU Affero General Public License for more details. | |
18 | | | |
19 | | You should have received a copy of the GNU Affero General Public | |
20 | | License and the CiviCRM Licensing Exception along | |
21 | | with this program; if not, contact CiviCRM LLC | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
25 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
28 | /** |
29 | * This api exposes functionality for interacting with the logging functionality. |
30 | * |
31 | * @package CiviCRM_APIv3 |
32 | */ |
33 | |
34 | /** |
35 | * Revert a log change. |
36 | * |
37 | * @param array $params |
38 | * |
39 | * @return array |
40 | * API Success Array |
41 | * @throws \API_Exception |
42 | * @throws \Civi\API\Exception\UnauthorizedException |
43 | */ |
44 | function civicrm_api3_logging_revert($params) { |
45 | $schema = new CRM_Logging_Schema(); |
99008b08 |
46 | $reverter = new CRM_Logging_Reverter($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params)); |
f16074c9 |
47 | $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact(); |
48 | $reverter->calculateDiffsFromLogConnAndDate($tables); |
93afbc3a |
49 | $reverter->revert(); |
50 | return civicrm_api3_create_success(1); |
51 | } |
29444295 |
52 | |
353918bc |
53 | /** |
54 | * Get a log change. |
55 | * |
56 | * @param array $params |
57 | * |
58 | * @throws \API_Exception |
59 | * @throws \Civi\API\Exception\UnauthorizedException |
60 | */ |
61 | function _civicrm_api3_logging_revert_spec(&$params) { |
62 | $params['log_conn_id'] = array( |
63 | 'title' => 'Logging Connection ID', |
64 | 'type' => CRM_Utils_Type::T_STRING, |
65 | 'api.required' => TRUE, |
66 | ); |
67 | $params['log_date'] = array( |
68 | 'title' => 'Logging Timestamp', |
69 | 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, |
70 | ); |
71 | $params['interval'] = array( |
72 | 'title' => ts('Interval (required if date is included)'), |
73 | 'type' => CRM_Utils_Type::T_STRING, |
74 | 'api.default' => '10 SECOND', |
75 | 'description' => ts('Used when log_date is passed in'), |
76 | ); |
f16074c9 |
77 | |
78 | $params['tables'] = array( |
79 | 'title' => ts('Tables to revert'), |
80 | 'type' => CRM_Utils_Type::T_STRING, |
81 | 'description' => ts('Tables to revert, if not set all contact-referring entities will be reverted'), |
82 | ); |
353918bc |
83 | } |
84 | |
29444295 |
85 | /** |
86 | * Get a log change. |
87 | * |
88 | * @param array $params |
89 | * |
90 | * @return array |
91 | * API Success Array |
92 | * @throws \API_Exception |
93 | * @throws \Civi\API\Exception\UnauthorizedException |
94 | */ |
95 | function civicrm_api3_logging_get($params) { |
96 | $schema = new CRM_Logging_Schema(); |
97 | $interval = (empty($params['log_date'])) ? NULL : $params['interval']; |
98 | $differ = new CRM_Logging_Differ($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params), $interval); |
f16074c9 |
99 | $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact(); |
100 | return civicrm_api3_create_success($differ->getAllChangesForConnection($tables)); |
29444295 |
101 | } |
102 | |
103 | /** |
104 | * Get a log change. |
105 | * |
106 | * @param array $params |
107 | * |
108 | * @throws \API_Exception |
109 | * @throws \Civi\API\Exception\UnauthorizedException |
110 | */ |
111 | function _civicrm_api3_logging_get_spec(&$params) { |
112 | $params['log_conn_id'] = array( |
113 | 'title' => 'Logging Connection ID', |
114 | 'type' => CRM_Utils_Type::T_STRING, |
115 | 'api.required' => TRUE, |
116 | ); |
117 | $params['log_date'] = array( |
118 | 'title' => 'Logging Timestamp', |
119 | 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, |
120 | ); |
121 | $params['interval'] = array( |
122 | 'title' => ts('Interval (required if date is included)'), |
123 | 'type' => CRM_Utils_Type::T_STRING, |
124 | 'api.default' => '10 SECOND', |
125 | 'description' => ts('Used when log_date is passed in'), |
126 | ); |
f16074c9 |
127 | $params['tables'] = array( |
128 | 'title' => ts('Tables to query'), |
129 | 'type' => CRM_Utils_Type::T_STRING, |
130 | 'description' => ts('Tables to query, if not set all contact-referring entities will be queried'), |
131 | ); |
29444295 |
132 | } |