From e299c1d0ca41b905673d94209a96aa19c70f65c0 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 17 Aug 2015 16:52:52 -0700 Subject: [PATCH] CRM-16373 - Config - Migrate `logging` to settings --- CRM/Admin/Form/Setting/Miscellaneous.php | 34 ++---------------- CRM/Logging/Schema.php | 44 ++++++++++++++++++++++++ settings/Core.setting.php | 20 +++++++++++ 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/CRM/Admin/Form/Setting/Miscellaneous.php b/CRM/Admin/Form/Setting/Miscellaneous.php index b554ff9ecd..cf4b71274e 100644 --- a/CRM/Admin/Form/Setting/Miscellaneous.php +++ b/CRM/Admin/Form/Setting/Miscellaneous.php @@ -47,6 +47,7 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting { 'versionCheck' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionCheckIgnoreDate' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'logging' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, @@ -73,16 +74,7 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting { public function buildQuickForm() { CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)')); - // also check if we can enable triggers - $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(FALSE); - - // FIXME: for now, disable logging for multilingual sites OR if triggers are not permittted - $domain = new CRM_Core_DAO_Domain(); - $domain->find(TRUE); - $attribs = $domain->locales || !$validTriggerPermission ? array('disabled' => 'disabled') : array(); - - $this->assign('validTriggerPermission', $validTriggerPermission); - $this->addYesNo('logging', ts('Logging'), NULL, NULL, $attribs); + $this->assign('validTriggerPermission', CRM_Core_DAO::checkTriggerViewPermission(FALSE)); $this->addElement( 'text', @@ -153,26 +145,4 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting { return $errors; } - - public function postProcess() { - // store the submitted values in an array - $config = CRM_Core_Config::singleton(); - $params = $this->controller->exportValues($this->_name); - - // get current logging status - $values = $this->exportValues(); - - parent::postProcess(); - - if ($config->logging != $values['logging']) { - $logging = new CRM_Logging_Schema(); - if ($values['logging']) { - $logging->enableLogging(); - } - else { - $logging->disableLogging(); - } - } - } - } diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 2b627b0b66..ee88ec526e 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -52,6 +52,50 @@ class CRM_Logging_Schema { 'civicrm_group' => array('cache_date', 'refresh_date'), ); + /** + * (Setting Callback - Validate) + * + * @param mixed $value + * @param array $fieldSpec + * @return bool + * @throws API_Exception + */ + public static function checkLoggingSupport(&$value, $fieldSpec) { + $domain = new CRM_Core_DAO_Domain(); + $domain->find(TRUE); + $disabled = $domain->locales || !(CRM_Core_DAO::checkTriggerViewPermission(FALSE)); + if ($disabled && $value) { + throw new API_Exception("In order to use this functionality, the installation's database user must have privileges to create triggers (in MySQL 5.0 – and in MySQL 5.1 if binary logging is enabled – this means the SUPER privilege). This install either does not seem to have the required privilege enabled. This functionality cannot be enabled on multilingual installations."); + } + return TRUE; + } + + /** + * (Setting Callback - On Change) + * Respond to changes in the "logging" setting. Set up or destroy + * triggers, etal. + * + * @param array $oldValue + * List of component names. + * @param array $newValue + * List of component names. + * @param array $metadata + * Specification of the setting (per *.settings.php). + */ + public static function onToggle($oldValue, $newValue, $metadata) { + if ($oldValue == $newValue) { + return; + } + + $logging = new CRM_Logging_Schema(); + if ($newValue) { + $logging->enableLogging(); + } + else { + $logging->disableLogging(); + } + } + /** * Populate $this->tables and $this->logs with current db state. */ diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 45b7d27a81..d015b5dfe2 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -720,6 +720,26 @@ return array( 'description' => 'When enabled, "empowered by CiviCRM" is displayed at the bottom of public forms.', 'help_text' => NULL, ), + 'logging' => array( + 'add' => '4.7', + 'prefetch' => 1, + 'help_text' => NULL, + 'is_domain' => 1, + 'is_contact' => 0, + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'logging', + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'html_type' => '', + 'default' => '0', + 'title' => 'Logging', + 'description' => 'If enabled, all actions will be logged with a complete record of changes.', + 'validate_callback' => 'CRM_Logging_Schema::checkLoggingSupport', + 'on_change' => array( + 'CRM_Logging_Schema::onToggle', + ), + ), 'wpLoadPhp' => array( 'group_name' => 'CiviCRM Preferences', 'group' => 'core', -- 2.25.1