Merge pull request #9629 from colemanw/CRM-19770
[civicrm-core.git] / api / v3 / Logging.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * @throws \API_Exception
58 * @throws \Civi\API\Exception\UnauthorizedException
59 */
60 function _civicrm_api3_logging_revert_spec(&$params) {
61 $params['log_conn_id'] = array(
62 'title' => 'Logging Connection ID',
63 'type' => CRM_Utils_Type::T_STRING,
64 'api.required' => TRUE,
65 );
66 $params['log_date'] = array(
67 'title' => 'Logging Timestamp',
68 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
69 );
70 $params['interval'] = array(
71 'title' => ts('Interval (required if date is included)'),
72 'type' => CRM_Utils_Type::T_STRING,
73 'api.default' => '10 SECOND',
74 'description' => ts('Used when log_date is passed in'),
75 );
76 }
77
78 /**
79 * Get a log change.
80 *
81 * @param array $params
82 *
83 * @return array
84 * API Success Array
85 * @throws \API_Exception
86 * @throws \Civi\API\Exception\UnauthorizedException
87 */
88 function civicrm_api3_logging_get($params) {
89 $schema = new CRM_Logging_Schema();
90 $interval = (empty($params['log_date'])) ? NULL : $params['interval'];
91 $differ = new CRM_Logging_Differ($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params), $interval);
92 return civicrm_api3_create_success($differ->getAllChangesForConnection($schema->getLogTablesForContact()));
93 }
94
95 /**
96 * Get a log change.
97 *
98 * @param array $params
99 *
100 * @throws \API_Exception
101 * @throws \Civi\API\Exception\UnauthorizedException
102 */
103 function _civicrm_api3_logging_get_spec(&$params) {
104 $params['log_conn_id'] = array(
105 'title' => 'Logging Connection ID',
106 'type' => CRM_Utils_Type::T_STRING,
107 'api.required' => TRUE,
108 );
109 $params['log_date'] = array(
110 'title' => 'Logging Timestamp',
111 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
112 );
113 $params['interval'] = array(
114 'title' => ts('Interval (required if date is included)'),
115 'type' => CRM_Utils_Type::T_STRING,
116 'api.default' => '10 SECOND',
117 'description' => ts('Used when log_date is passed in'),
118 );
119 }