From 9c305ba15ad6a37a94785c7bae327af3badd7d29 Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 19 Dec 2007 22:32:43 +0000 Subject: [PATCH] MDL-12655 set_config() should cast values to string because get_config does that too; merged from MOODLE_19_STABLE --- lib/adminlib.php | 25 +++++++++++++++++++++---- lib/moodlelib.php | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index 5ffa3ae7e5..56848ada6d 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2162,6 +2162,19 @@ class admin_setting_configselect extends admin_setting { $defaultinfo = ''; } + $current = $this->get_setting(); + $warning = ''; + if (is_null($current)) { + //first run + } else if (empty($current) and (array_key_exists('', $this->choices) or array_key_exists(0, $this->choices))) { + // no warning + } else if (!array_key_exists($current, $this->choices)) { + $warning = get_string('warningcurrentsetting', 'admin', s($current)); + if (!is_null($default) and $data==$current) { + $data = $default; // use default instead of first value when showing the form + } + } + $return = '
'.$defaultinfo.'
'; - return format_admin_setting($this, $this->visiblename, $return, $this->description); + return format_admin_setting($this, $this->visiblename, $return, $this->description, true, $warning); } } @@ -4243,7 +4256,7 @@ function apply_default_exception_settings($defaults) { * @param string $description * @param bool $label link label to id */ -function format_admin_setting($setting, $title='', $form='', $description='', $label=true) { +function format_admin_setting($setting, $title='', $form='', $description='', $label=true, $warning='') { global $CFG; $name = $setting->name; @@ -4257,14 +4270,18 @@ function format_admin_setting($setting, $title='', $form='', $description='', $l } if (empty($setting->plugin) and array_key_exists($name, $CFG->config_php_settings)) { - $override = ''.get_string('configoverride', 'admin').''; + $override = '
'.get_string('configoverride', 'admin').'
'; } else { $override = ''; } + if ($warning !== '') { + $warning = '
'.$warning.'
'; + } + $str = '
-
+
'.$form.'
'.$description.'
'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index a5f4eac8b3..9dda931f39 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -616,7 +616,7 @@ function set_config($name, $value, $plugin=NULL) { if (is_null($value)) { unset($CFG->$name); } else { - $CFG->$name = $value; + $CFG->$name = (string)$value; // settings from db are always strings } } -- 2.39.5