From: eileen Date: Thu, 31 Mar 2016 04:32:04 +0000 (+1300) Subject: CRM-18332 - Logging report - Extract methods storeDB() & revert() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e480ef0993ec2dd56cd747c4296c2ded2624cb84;p=civicrm-core.git CRM-18332 - Logging report - Extract methods storeDB() & revert() --- diff --git a/CRM/Logging/ReportDetail.php b/CRM/Logging/ReportDetail.php index d3dc85cf32..72ee23e690 100644 --- a/CRM/Logging/ReportDetail.php +++ b/CRM/Logging/ReportDetail.php @@ -29,8 +29,6 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2016 - * $Id$ - * */ class CRM_Logging_ReportDetail extends CRM_Report_Form { protected $cid; @@ -50,13 +48,18 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form { protected $summary; /** + * Don't display the Add these contacts to Group button. + * + * @var bool + */ + protected $_add2groupSupported = FALSE; + + /** + * Class constructor. */ public function __construct() { - // don’t display the ‘Add these Contacts to Group’ button - $this->_add2groupSupported = FALSE; - $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN); - $this->db = $dsn['database']; + $this->storeDB(); $this->log_conn_id = CRM_Utils_Request::retrieve('log_conn_id', 'Integer', CRM_Core_DAO::$_nullObject); $this->log_date = CRM_Utils_Request::retrieve('log_date', 'String', CRM_Core_DAO::$_nullObject); @@ -90,16 +93,8 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form { ); CRM_Utils_System::appendBreadCrumb($breadcrumb); - if (CRM_Utils_Request::retrieve('revert', 'Boolean', CRM_Core_DAO::$_nullObject)) { - $reverter = new CRM_Logging_Reverter($this->log_conn_id, $this->log_date); - $reverter->revert($this->tables); - CRM_Core_Session::setStatus(ts('The changes have been reverted.'), ts('Reverted'), 'success'); - if ($this->cid) { - CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&selectedChild=log&cid={$this->cid}", FALSE, NULL, FALSE)); - } - else { - CRM_Utils_System::redirect(CRM_Report_Utils_Report::getNextUrl($this->summary, 'reset=1', FALSE, TRUE)); - } + if (CRM_Utils_Request::retrieve('revert', 'Boolean')) { + $this->revert(); } // make sure the report works even without the params @@ -225,11 +220,6 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form { public function buildQuickForm() { parent::buildQuickForm(); - $params = array( - 1 => array($this->log_conn_id, 'Integer'), - 2 => array($this->log_date, 'String'), - ); - $this->assign('whom_url', CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->cid}")); $this->assign('who_url', CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->altered_by_id}")); $this->assign('whom_name', $this->altered_name); @@ -242,4 +232,27 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form { $this->assign('revertConfirm', ts('Are you sure you want to revert all changes?')); } + /** + * Store the dsn for the logging database in $this->db. + */ + protected function storeDB() { + $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN); + $this->db = $dsn['database']; + } + + /** + * Revert the changes defined by the parameters. + */ + protected function revert() { + $reverter = new CRM_Logging_Reverter($this->log_conn_id, $this->log_date); + $reverter->revert($this->tables); + CRM_Core_Session::setStatus(ts('The changes have been reverted.'), ts('Reverted'), 'success'); + if ($this->cid) { + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&selectedChild=log&cid={$this->cid}", FALSE, NULL, FALSE)); + } + else { + CRM_Utils_System::redirect(CRM_Report_Utils_Report::getNextUrl($this->summary, 'reset=1', FALSE, TRUE)); + } + } + } diff --git a/CRM/Logging/Reverter.php b/CRM/Logging/Reverter.php index d16bb7d10e..1c35fdd6ed 100644 --- a/CRM/Logging/Reverter.php +++ b/CRM/Logging/Reverter.php @@ -29,8 +29,6 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2016 - * $Id$ - * */ class CRM_Logging_Reverter { private $db;