From: martinlanghoff Date: Wed, 14 Nov 2007 22:10:21 +0000 (+0000) Subject: MDL-9399 moodlelib: set_config() deletes config entries if the value is NULL X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6fd511eb1cc32b2b7ab54785e0cb5e5706f4d067;p=moodle.git MDL-9399 moodlelib: set_config() deletes config entries if the value is NULL New! Improved! If you pass NULL as the value, it will delete the config entry for you. --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 2d00b35cf9..73003f379a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -597,6 +597,8 @@ function clean_param($param, $type) { * Can also be used to update keys for plugin-scoped configs in config_plugin table. * In that case it doesn't affect $CFG. * + * A NULL value will delete the entry. + * * @param string $name the key to set * @param string $value the value to set (without magic quotes) * @param string $plugin (optional) the plugin scope @@ -612,8 +614,16 @@ function set_config($name, $value, $plugin=NULL) { $CFG->$name = $value; // So it's defined for this invocation at least if (get_field('config', 'name', 'name', $name)) { - return set_field('config', 'value', addslashes($value), 'name', $name); + if ($value===null) { + unset($CFG->$name); + return delete_records('config', 'name', $name); + } else { + return set_field('config', 'value', addslashes($value), 'name', $name); + } } else { + if ($value===null) { + return true; + } $config = new object(); $config->name = $name; $config->value = addslashes($value); @@ -621,8 +631,15 @@ function set_config($name, $value, $plugin=NULL) { } } else { // plugin scope if ($id = get_field('config_plugins', 'id', 'name', $name, 'plugin', $plugin)) { - return set_field('config_plugins', 'value', addslashes($value), 'id', $id); + if ($value===null) { + return delete_records('config_plugins', 'name', $name, 'plugin', $plugin); + } else { + return set_field('config_plugins', 'value', addslashes($value), 'id', $id); + } } else { + if ($value===null) { + return true; + } $config = new object(); $config->plugin = addslashes($plugin); $config->name = $name;