Merge pull request #9769 from scardinius/crm-19958
[civicrm-core.git] / api / v3 / Logging.php
index c334e6283dcabb78076d5ba3e8d5ca9ea831c5fd..3287b8794f675febda5dc29548e21dbcc7077f8f 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -44,7 +44,8 @@
 function civicrm_api3_logging_revert($params) {
   $schema = new CRM_Logging_Schema();
   $reverter = new CRM_Logging_Reverter($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params));
-  $reverter->calculateDiffsFromLogConnAndDate($schema->getLogTablesForContact());
+  $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact();
+  $reverter->calculateDiffsFromLogConnAndDate($tables);
   $reverter->revert();
   return civicrm_api3_create_success(1);
 }
@@ -73,6 +74,12 @@ function _civicrm_api3_logging_revert_spec(&$params) {
     'api.default' => '10 SECOND',
     'description' => ts('Used when log_date is passed in'),
   );
+
+  $params['tables'] = array(
+    'title' => ts('Tables to revert'),
+    'type' => CRM_Utils_Type::T_STRING,
+    'description' => ts('Tables to revert, if not set all contact-referring entities will be reverted'),
+  );
 }
 
 /**
@@ -89,7 +96,8 @@ function civicrm_api3_logging_get($params) {
   $schema = new CRM_Logging_Schema();
   $interval = (empty($params['log_date'])) ? NULL : $params['interval'];
   $differ = new CRM_Logging_Differ($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params), $interval);
-  return civicrm_api3_create_success($differ->getAllChangesForConnection($schema->getLogTablesForContact()));
+  $tables = !empty($params['tables']) ? (array) $params['tables'] : $schema->getLogTablesForContact();
+  return civicrm_api3_create_success($differ->getAllChangesForConnection($tables));
 }
 
 /**
@@ -116,4 +124,9 @@ function _civicrm_api3_logging_get_spec(&$params) {
     'api.default' => '10 SECOND',
     'description' => ts('Used when log_date is passed in'),
   );
+  $params['tables'] = array(
+    'title' => ts('Tables to query'),
+    'type' => CRM_Utils_Type::T_STRING,
+    'description' => ts('Tables to query, if not set all contact-referring entities will be queried'),
+  );
 }