Skip to content

Commit

Permalink
QA fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Aug 29, 2017
1 parent e439a7c commit 239ca23
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
22 changes: 4 additions & 18 deletions CRM/Admin/Form/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
Expand Down
23 changes: 0 additions & 23 deletions CRM/Admin/Form/Setting/Debugging.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
29 changes: 29 additions & 0 deletions CRM/Core/BAO/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

}
4 changes: 3 additions & 1 deletion Civi/Core/SettingsBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions api/v3/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
3 changes: 3 additions & 0 deletions settings/Developer.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 239ca23

Please sign in to comment.