3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * This api exposes functionality for interacting with the logging functionality.
31 * @package CiviCRM_APIv3
35 * Revert a log change.
37 * @param array $params
41 * @throws \API_Exception
42 * @throws \Civi\API\Exception\UnauthorizedException
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 $tables = !empty($params['tables']) ?
(array) $params['tables'] : $schema->getLogTablesForContact();
48 $reverter->calculateDiffsFromLogConnAndDate($tables);
50 return civicrm_api3_create_success(1);
56 * @param array $params
58 * @throws \API_Exception
59 * @throws \Civi\API\Exception\UnauthorizedException
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,
67 $params['log_date'] = array(
68 'title' => 'Logging Timestamp',
69 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
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'),
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'),
88 * @param array $params
92 * @throws \API_Exception
93 * @throws \Civi\API\Exception\UnauthorizedException
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);
99 $tables = !empty($params['tables']) ?
(array) $params['tables'] : $schema->getLogTablesForContact();
100 return civicrm_api3_create_success($differ->getAllChangesForConnection($tables));
106 * @param array $params
108 * @throws \API_Exception
109 * @throws \Civi\API\Exception\UnauthorizedException
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,
117 $params['log_date'] = array(
118 'title' => 'Logging Timestamp',
119 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
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'),
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'),