<?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;
*
* @var array
*/
- private $diffs = array();
+ private $diffs = [];
/**
* Class constructor.
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;
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;
// 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) {
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
$inserts[$field] = "%$counter";
$updates[] = "{$field} = {$fldVal}";
if ($fldVal != 'DEFAULT') {
- $params[$counter] = array($value, $ctypes[$table][$field]);
+ $params[$counter] = [$value, $ctypes[$table][$field]];
}
$counter++;
}