mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-25290 conversion: Converted config to use MUC
This commit is contained in:
parent
9da506c2a3
commit
007bfe8b4d
6 changed files with 76 additions and 57 deletions
|
@ -1306,7 +1306,7 @@ function set_config($name, $value, $plugin=NULL) {
|
|||
$DB->insert_record('config', $config, false);
|
||||
}
|
||||
}
|
||||
|
||||
cache_helper::invalidate_by_definition('core', 'config', array(), 'core');
|
||||
} else { // plugin scope
|
||||
if ($id = $DB->get_field('config_plugins', 'id', array('name'=>$name, 'plugin'=>$plugin))) {
|
||||
if ($value===null) {
|
||||
|
@ -1323,6 +1323,7 @@ function set_config($name, $value, $plugin=NULL) {
|
|||
$DB->insert_record('config_plugins', $config, false);
|
||||
}
|
||||
}
|
||||
cache_helper::invalidate_by_definition('core', 'config', array(), $plugin);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1345,63 +1346,55 @@ function set_config($name, $value, $plugin=NULL) {
|
|||
function get_config($plugin, $name = NULL) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// normalise component name
|
||||
if ($plugin === 'moodle' or $plugin === 'core') {
|
||||
$plugin = NULL;
|
||||
}
|
||||
|
||||
if (!empty($name)) { // the user is asking for a specific value
|
||||
if (!empty($plugin)) {
|
||||
if (isset($CFG->forced_plugin_settings[$plugin]) and array_key_exists($name, $CFG->forced_plugin_settings[$plugin])) {
|
||||
// setting forced in config file
|
||||
return $CFG->forced_plugin_settings[$plugin][$name];
|
||||
} else {
|
||||
return $DB->get_field('config_plugins', 'value', array('plugin'=>$plugin, 'name'=>$name));
|
||||
}
|
||||
} else {
|
||||
if (array_key_exists($name, $CFG->config_php_settings)) {
|
||||
// setting force in config file
|
||||
return $CFG->config_php_settings[$name];
|
||||
} else {
|
||||
return $DB->get_field('config', 'value', array('name'=>$name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the user is after a recordset
|
||||
if ($plugin) {
|
||||
$localcfg = $DB->get_records_menu('config_plugins', array('plugin'=>$plugin), '', 'name,value');
|
||||
if (isset($CFG->forced_plugin_settings[$plugin])) {
|
||||
foreach($CFG->forced_plugin_settings[$plugin] as $n=>$v) {
|
||||
if (is_null($v) or is_array($v) or is_object($v)) {
|
||||
// we do not want any extra mess here, just real settings that could be saved in db
|
||||
unset($localcfg[$n]);
|
||||
} else {
|
||||
//convert to string as if it went through the DB
|
||||
$localcfg[$n] = (string)$v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($localcfg) {
|
||||
return (object)$localcfg;
|
||||
} else {
|
||||
return new stdClass();
|
||||
}
|
||||
|
||||
if ($plugin === 'moodle' || $plugin === 'core' || empty($plugin)) {
|
||||
$forced =& $CFG->config_php_settings;
|
||||
$iscore = true;
|
||||
$plugin = 'core';
|
||||
} else {
|
||||
// this part is not really used any more, but anyway...
|
||||
$localcfg = $DB->get_records_menu('config', array(), '', 'name,value');
|
||||
foreach($CFG->config_php_settings as $n=>$v) {
|
||||
if (is_null($v) or is_array($v) or is_object($v)) {
|
||||
// we do not want any extra mess here, just real settings that could be saved in db
|
||||
unset($localcfg[$n]);
|
||||
} else {
|
||||
//convert to string as if it went through the DB
|
||||
$localcfg[$n] = (string)$v;
|
||||
}
|
||||
if (array_key_exists($plugin, $CFG->forced_plugin_settings)) {
|
||||
$forced =& $CFG->forced_plugin_settings[$plugin];
|
||||
} else {
|
||||
$forced = array();
|
||||
}
|
||||
return (object)$localcfg;
|
||||
$iscore = false;
|
||||
}
|
||||
|
||||
if (!empty($name) && array_key_exists($name, $forced)) {
|
||||
return (string)$forced[$name];
|
||||
}
|
||||
|
||||
$cache = cache::make('core', 'config');
|
||||
$result = $cache->get($plugin);
|
||||
if (!$result) {
|
||||
// the user is after a recordset
|
||||
$result = new stdClass;
|
||||
if (!$iscore) {
|
||||
$result = $DB->get_records_menu('config_plugins', array('plugin'=>$plugin), '', 'name,value');
|
||||
} else {
|
||||
// this part is not really used any more, but anyway...
|
||||
$result = $DB->get_records_menu('config', array(), '', 'name,value');;
|
||||
}
|
||||
$cache->set($plugin, $result);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
if (array_key_exists($name, $result)) {
|
||||
return $result[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($forced as $key => $value) {
|
||||
if (is_null($value) or is_array($value) or is_object($value)) {
|
||||
// we do not want any extra mess here, just real settings that could be saved in db
|
||||
unset($result[$key]);
|
||||
} else {
|
||||
//convert to string as if it went through the DB
|
||||
$result[$key] = (string)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return (object)$result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1418,8 +1411,10 @@ function unset_config($name, $plugin=NULL) {
|
|||
if (empty($plugin)) {
|
||||
unset($CFG->$name);
|
||||
$DB->delete_records('config', array('name'=>$name));
|
||||
cache_helper::invalidate_by_definition('core', 'config', array(), 'core');
|
||||
} else {
|
||||
$DB->delete_records('config_plugins', array('name'=>$name, 'plugin'=>$plugin));
|
||||
cache_helper::invalidate_by_definition('core', 'config', array(), $plugin);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1433,10 +1428,15 @@ function unset_config($name, $plugin=NULL) {
|
|||
*/
|
||||
function unset_all_config_for_plugin($plugin) {
|
||||
global $DB;
|
||||
// Delete from the obvious config_plugins first
|
||||
$DB->delete_records('config_plugins', array('plugin' => $plugin));
|
||||
// Next delete any suspect settings from config
|
||||
$like = $DB->sql_like('name', '?', true, true, false, '|');
|
||||
$params = array($DB->sql_like_escape($plugin.'_', '|') . '%');
|
||||
$DB->delete_records_select('config', $like, $params);
|
||||
// Finally clear both the plugin cache and the core cache (suspect settings now removed from core).
|
||||
cache_helper::invalidate_by_definition('core', 'config', array(), array('core', $plugin));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue