Merge pull request #18963 from samuelsov/nli18n
[civicrm-core.git] / CRM / Logging / Reverter.php
index 61d87c6d4a3bade19ef537b481bc648024a37919..eb1c9dedc16c1f9964e89f519075838fc0821ec1 100644 (file)
@@ -1,34 +1,18 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
- |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 class CRM_Logging_Reverter {
   private $db;
@@ -40,7 +24,7 @@ class CRM_Logging_Reverter {
    *
    * @var array
    */
-  private $diffs = array();
+  private $diffs = [];
 
   /**
    * Class constructor.
@@ -49,7 +33,8 @@ class CRM_Logging_Reverter {
    * @param $log_date
    */
   public function __construct($log_conn_id, $log_date) {
-    $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN);
+    $dsn = defined('CIVICRM_LOGGING_DSN') ? CRM_Utils_SQL::autoSwitchDSN(CIVICRM_LOGGING_DSN) : CRM_Utils_SQL::autoSwitchDSN(CIVICRM_DSN);
+    $dsn = DB::parseDSN($dsn);
     $this->db = $dsn['database'];
     $this->log_conn_id = $log_conn_id;
     $this->log_date = $log_date;
@@ -81,24 +66,24 @@ class CRM_Logging_Reverter {
   public function revert() {
 
     // get custom data tables, columns and types
-    $ctypes = array();
+    $ctypes = [];
     $dao = CRM_Core_DAO::executeQuery('SELECT table_name, column_name, data_type FROM civicrm_custom_group cg JOIN civicrm_custom_field cf ON (cf.custom_group_id = cg.id)');
     while ($dao->fetch()) {
       if (!isset($ctypes[$dao->table_name])) {
-        $ctypes[$dao->table_name] = array('entity_id' => 'Integer');
+        $ctypes[$dao->table_name] = ['entity_id' => 'Integer'];
       }
       $ctypes[$dao->table_name][$dao->column_name] = $dao->data_type;
     }
 
     $diffs = $this->diffs;
-    $deletes = array();
-    $reverts = array();
+    $deletes = [];
+    $reverts = [];
     foreach ($diffs as $table => $changes) {
       foreach ($changes as $change) {
         switch ($change['action']) {
           case 'Insert':
             if (!isset($deletes[$table])) {
-              $deletes[$table] = array();
+              $deletes[$table] = [];
             }
             $deletes[$table][] = $change['id'];
             break;
@@ -106,10 +91,10 @@ class CRM_Logging_Reverter {
           case 'Delete':
           case 'Update':
             if (!isset($reverts[$table])) {
-              $reverts[$table] = array();
+              $reverts[$table] = [];
             }
             if (!isset($reverts[$table][$change['id']])) {
-              $reverts[$table][$change['id']] = array('log_action' => $change['action']);
+              $reverts[$table][$change['id']] = ['log_action' => $change['action']];
             }
             $reverts[$table][$change['id']][$change['field']] = $change['from'];
             break;
@@ -128,7 +113,7 @@ class CRM_Logging_Reverter {
         // DAO-based tables
 
         case (($tableDAO = CRM_Core_DAO_AllCoreTables::getClassForTable($table)) != FALSE):
-          $dao = new $tableDAO ();
+          $dao = new $tableDAO();
           foreach ($row as $id => $changes) {
             $dao->id = $id;
             foreach ($changes as $field => $value) {
@@ -157,9 +142,9 @@ class CRM_Logging_Reverter {
 
         case in_array($table, array_keys($ctypes)):
           foreach ($row as $id => $changes) {
-            $inserts = array('id' => '%1');
-            $updates = array();
-            $params = array(1 => array($id, 'Integer'));
+            $inserts = ['id' => '%1'];
+            $updates = [];
+            $params = [1 => [$id, 'Integer']];
             $counter = 2;
             foreach ($changes as $field => $value) {
               // don’t try reverting a field that’s no longer there
@@ -184,7 +169,7 @@ class CRM_Logging_Reverter {
               $inserts[$field] = "%$counter";
               $updates[] = "{$field} = {$fldVal}";
               if ($fldVal != 'DEFAULT') {
-                $params[$counter] = array($value, $ctypes[$table][$field]);
+                $params[$counter] = [$value, $ctypes[$table][$field]];
               }
               $counter++;
             }