From 239ca23d6fcd5aed088c7fc2d8fffd16e81aeb09 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Tue, 29 Aug 2017 13:06:41 +0530 Subject: [PATCH] QA fixes --- CRM/Admin/Form/Setting.php | 22 ++++----------------- CRM/Admin/Form/Setting/Debugging.php | 23 ---------------------- CRM/Core/BAO/Setting.php | 29 ++++++++++++++++++++++++++++ Civi/Core/SettingsBag.php | 4 +++- api/v3/Setting.php | 6 ++++++ settings/Developer.setting.php | 3 +++ 6 files changed, 45 insertions(+), 42 deletions(-) diff --git a/CRM/Admin/Form/Setting.php b/CRM/Admin/Form/Setting.php index c378b53d8061..ccfee7997eea 100644 --- a/CRM/Admin/Form/Setting.php +++ b/CRM/Admin/Form/Setting.php @@ -98,23 +98,9 @@ public function buildQuickForm() { foreach ($settingMetaData as $setting => $props) { if (isset($props['quick_form_type'])) { if (isset($props['pseudoconstant'])) { - if (array_key_exists('optionGroupName', $props['pseudoconstant'])) { - $optionValues = civicrm_api3('OptionValue', 'get', array( - 'return' => array("label", "value"), - 'option_group_id' => $setting, - )); - if ($optionValues['count'] > 0) { - foreach ($optionValues['values'] as $key => $values) { - $vals[$values['value']] = $values['label']; - } - $options['values'] = $vals; - } - } - else { - $options = civicrm_api3('Setting', 'getoptions', array( - 'field' => $setting, - )); - } + $options = civicrm_api3('Setting', 'getoptions', array( + 'field' => $setting, + )); } else { $options = NULL; @@ -132,7 +118,7 @@ public function buildQuickForm() { } elseif ($add == 'addSelect') { $element = $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props)); - if (defined('CIVICRM_ENVIRONMENT')) { + if ($setting == 'environment' && defined('CIVICRM_ENVIRONMENT')) { $element->freeze(); CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info'); } diff --git a/CRM/Admin/Form/Setting/Debugging.php b/CRM/Admin/Form/Setting/Debugging.php index 0d7219a2f3ec..fe3877356f24 100644 --- a/CRM/Admin/Form/Setting/Debugging.php +++ b/CRM/Admin/Form/Setting/Debugging.php @@ -56,27 +56,4 @@ public function buildQuickForm() { parent::buildQuickForm(); } - /** - * Process the form submission. - */ - public function postProcess() { - $params = $this->controller->exportValues($this->_name); - - if ($params['environment'] != 'Production') { - $mailing = Civi::settings()->get('mailing_backend'); - if ($mailing['outBound_option'] != 2) { - Civi::settings()->set('mailing_backend_store', $mailing); - } - Civi::settings()->set('mailing_backend', array('outBound_option' => CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED)); - CRM_Core_Session::setStatus(ts('Outbound emails have been disabled. Scheduled jobs will not run unless runInNonProductionEnvironment=TRUE is added as a parameter for a specific job'), ts("Non-production environment set"), "success"); - } - else { - $mailing = Civi::settings()->get('mailing_backend_store'); - if ($mailing) { - Civi::settings()->set('mailing_backend', $mailing); - } - } - parent::postProcess(); - } - } diff --git a/CRM/Core/BAO/Setting.php b/CRM/Core/BAO/Setting.php index 9b45f11aa8ca..f83aebd2edb2 100644 --- a/CRM/Core/BAO/Setting.php +++ b/CRM/Core/BAO/Setting.php @@ -514,4 +514,33 @@ public static function isAPIJobAllowedToRun($params) { } } + /** + * Setting Callback - On Change. + * + * Respond to changes in the "environment" setting. + * + * @param array $oldValue + * Value of old environment mode. + * @param array $newValue + * Value of new environment mode. + * @param array $metadata + * Specification of the setting (per *.settings.php). + */ + public static function onChangeEnvironmentSetting($oldValue, $newValue, $metadata) { + if ($newValue != 'Production') { + $mailing = Civi::settings()->get('mailing_backend'); + if ($mailing['outBound_option'] != 2) { + Civi::settings()->set('mailing_backend_store', $mailing); + } + Civi::settings()->set('mailing_backend', array('outBound_option' => CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED)); + CRM_Core_Session::setStatus(ts('Outbound emails have been disabled. Scheduled jobs will not run unless runInNonProductionEnvironment=TRUE is added as a parameter for a specific job'), ts("Non-production environment set"), "success"); + } + else { + $mailing = Civi::settings()->get('mailing_backend_store'); + if ($mailing) { + Civi::settings()->set('mailing_backend', $mailing); + } + } + } + } diff --git a/Civi/Core/SettingsBag.php b/Civi/Core/SettingsBag.php index 14289499244f..2aee1eb1c205 100644 --- a/Civi/Core/SettingsBag.php +++ b/Civi/Core/SettingsBag.php @@ -352,7 +352,9 @@ protected function setDb($name, $value) { } $dao->find(TRUE); - if (isset($metadata['on_change']) && !($value == 0 && ($dao->value === NULL || unserialize($dao->value) == 0))) { + // string comparison with 0 always return true, so to be ensure the type use === + // ref - https://stackoverflow.com/questions/8671942/php-string-comparasion-to-0-integer-returns-true + if (isset($metadata['on_change']) && !($value === 0 && ($dao->value === NULL || unserialize($dao->value) == 0))) { foreach ($metadata['on_change'] as $callback) { call_user_func( \Civi\Core\Resolver::singleton()->get($callback), diff --git a/api/v3/Setting.php b/api/v3/Setting.php index e8d85801e178..0677d2ffa049 100644 --- a/api/v3/Setting.php +++ b/api/v3/Setting.php @@ -160,6 +160,12 @@ function civicrm_api3_setting_getoptions($params) { $values = Civi\Core\Resolver::singleton()->call($pseudoconstant['callback'], array()); return civicrm_api3_create_success($values, $params, 'Setting', 'getoptions'); } + elseif (!empty($pseudoconstant['optionGroupName'])) { + return civicrm_api3_create_success( + CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], FALSE, FALSE, TRUE), + $params, 'Setting', 'getoptions' + ); + } throw new API_Exception("The field '" . $params['field'] . "' uses an unsupported option list."); } diff --git a/settings/Developer.setting.php b/settings/Developer.setting.php index 2c0902ba6a24..9a47e7916e62 100644 --- a/settings/Developer.setting.php +++ b/settings/Developer.setting.php @@ -116,6 +116,9 @@ 'is_domain' => 1, 'is_contact' => 0, 'description' => "Setting to define the environment in which this CiviCRM instance is running.", + 'on_change' => array( + 'CRM_Core_BAO_Setting::onChangeEnvironmentSetting', + ), ), 'fatalErrorHandler' => array( 'group_name' => 'Developer Preferences',