32bab67c39fa87562a8bd24dbc9b870575272add
[civicrm-core.git] / api / v3 / Logging.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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();
46 $reverter = new CRM_Logging_Reverter($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params));
47 $reverter->calculateDiffsFromLogConnAndDate($schema->getLogTablesForContact());
48 $reverter->revert();
49 return civicrm_api3_create_success(1);
50 }
51
52 /**
53 * Get a log change.
54 *
55 * @param array $params
56 *
57 * @return array
58 * API Success Array
59 * @throws \API_Exception
60 * @throws \Civi\API\Exception\UnauthorizedException
61 */
62 function civicrm_api3_logging_get($params) {
63 $schema = new CRM_Logging_Schema();
64 $interval = (empty($params['log_date'])) ? NULL : $params['interval'];
65 $differ = new CRM_Logging_Differ($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params), $interval);
66 return civicrm_api3_create_success($differ->getAllChangesForConnection($schema->getLogTablesForContact()));
67 }
68
69 /**
70 * Get a log change.
71 *
72 * @param array $params
73 *
74 * @throws \API_Exception
75 * @throws \Civi\API\Exception\UnauthorizedException
76 */
77 function _civicrm_api3_logging_get_spec(&$params) {
78 $params['log_conn_id'] = array(
79 'title' => 'Logging Connection ID',
80 'type' => CRM_Utils_Type::T_STRING,
81 'api.required' => TRUE,
82 );
83 $params['log_date'] = array(
84 'title' => 'Logging Timestamp',
85 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
86 );
87 $params['interval'] = array(
88 'title' => ts('Interval (required if date is included)'),
89 'type' => CRM_Utils_Type::T_STRING,
90 'api.default' => '10 SECOND',
91 'description' => ts('Used when log_date is passed in'),
92 );
93 }