mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +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
|
@ -150,6 +150,8 @@ class block_section_links extends block_base {
|
||||||
global $DB;
|
global $DB;
|
||||||
// TODO: Move these config settings to proper ones using component name
|
// TODO: Move these config settings to proper ones using component name
|
||||||
$DB->delete_records('config_plugins', array('plugin' => 'blocks/section_links'));
|
$DB->delete_records('config_plugins', array('plugin' => 'blocks/section_links'));
|
||||||
|
// Have to manually purge the cache as well
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), 'blocks/section_links');
|
||||||
}
|
}
|
||||||
|
|
||||||
function has_config() {
|
function has_config() {
|
||||||
|
|
|
@ -34,6 +34,7 @@ $string['area'] = 'Area';
|
||||||
$string['caching'] = 'Caching';
|
$string['caching'] = 'Caching';
|
||||||
$string['cacheadmin'] = 'Cache administration';
|
$string['cacheadmin'] = 'Cache administration';
|
||||||
$string['cacheconfig'] = 'Configuration';
|
$string['cacheconfig'] = 'Configuration';
|
||||||
|
$string['cachedef_config'] = 'Config settings';
|
||||||
$string['cachedef_databasemeta'] = 'Database meta information';
|
$string['cachedef_databasemeta'] = 'Database meta information';
|
||||||
$string['cachedef_eventinvalidation'] = 'Event invalidation';
|
$string['cachedef_eventinvalidation'] = 'Event invalidation';
|
||||||
$string['cachedef_locking'] = 'Locking';
|
$string['cachedef_locking'] = 'Locking';
|
||||||
|
|
|
@ -75,4 +75,15 @@ $definitions = array(
|
||||||
'datasource' => 'question_finder',
|
'datasource' => 'question_finder',
|
||||||
'datasourcefile' => 'question/engine/bank.php',
|
'datasourcefile' => 'question/engine/bank.php',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Used to store data from the config + config_plugins table in the database.
|
||||||
|
// The key used is the component:
|
||||||
|
// - core for all core config settings
|
||||||
|
// - plugin component for all plugin settings.
|
||||||
|
// Persistence is used because normally several settings within a script.
|
||||||
|
'config' => array(
|
||||||
|
'mode' => cache_store::MODE_APPLICATION,
|
||||||
|
'persistent' => true,
|
||||||
|
'simpledata' => true
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -284,6 +284,7 @@ function message_update_providers($component='moodle') {
|
||||||
$DB->delete_records('message_providers', array('id' => $dbprovider->id));
|
$DB->delete_records('message_providers', array('id' => $dbprovider->id));
|
||||||
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_{$component}_{$dbprovider->name}_%"));
|
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_{$component}_{$dbprovider->name}_%"));
|
||||||
$DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_{$component}_{$dbprovider->name}_%"));
|
$DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_{$component}_{$dbprovider->name}_%"));
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), 'message');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -574,6 +575,8 @@ function message_provider_uninstall($component) {
|
||||||
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_{$component}_%"));
|
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_{$component}_%"));
|
||||||
$DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_{$component}_%"));
|
$DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_{$component}_%"));
|
||||||
$transaction->allow_commit();
|
$transaction->allow_commit();
|
||||||
|
// Purge all messaging settings from the caches. They are stored by plugin so we have to clear all message settings.
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), 'message');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -591,4 +594,6 @@ function message_processor_uninstall($name) {
|
||||||
// defaults, they will be removed on the next attempt to update the preferences
|
// defaults, they will be removed on the next attempt to update the preferences
|
||||||
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("{$name}_provider_%"));
|
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("{$name}_provider_%"));
|
||||||
$transaction->allow_commit();
|
$transaction->allow_commit();
|
||||||
|
// Purge all messaging settings from the caches. They are stored by plugin so we have to clear all message settings.
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), array('message', "message_{$name}"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1306,7 +1306,7 @@ function set_config($name, $value, $plugin=NULL) {
|
||||||
$DB->insert_record('config', $config, false);
|
$DB->insert_record('config', $config, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), 'core');
|
||||||
} else { // plugin scope
|
} else { // plugin scope
|
||||||
if ($id = $DB->get_field('config_plugins', 'id', array('name'=>$name, 'plugin'=>$plugin))) {
|
if ($id = $DB->get_field('config_plugins', 'id', array('name'=>$name, 'plugin'=>$plugin))) {
|
||||||
if ($value===null) {
|
if ($value===null) {
|
||||||
|
@ -1323,6 +1323,7 @@ function set_config($name, $value, $plugin=NULL) {
|
||||||
$DB->insert_record('config_plugins', $config, false);
|
$DB->insert_record('config_plugins', $config, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), $plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1345,63 +1346,55 @@ function set_config($name, $value, $plugin=NULL) {
|
||||||
function get_config($plugin, $name = NULL) {
|
function get_config($plugin, $name = NULL) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// normalise component name
|
if ($plugin === 'moodle' || $plugin === 'core' || empty($plugin)) {
|
||||||
if ($plugin === 'moodle' or $plugin === 'core') {
|
$forced =& $CFG->config_php_settings;
|
||||||
$plugin = NULL;
|
$iscore = true;
|
||||||
|
$plugin = 'core';
|
||||||
|
} else {
|
||||||
|
if (array_key_exists($plugin, $CFG->forced_plugin_settings)) {
|
||||||
|
$forced =& $CFG->forced_plugin_settings[$plugin];
|
||||||
|
} else {
|
||||||
|
$forced = array();
|
||||||
|
}
|
||||||
|
$iscore = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($name)) { // the user is asking for a specific value
|
if (!empty($name) && array_key_exists($name, $forced)) {
|
||||||
if (!empty($plugin)) {
|
return (string)$forced[$name];
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cache = cache::make('core', 'config');
|
||||||
|
$result = $cache->get($plugin);
|
||||||
|
if (!$result) {
|
||||||
// the user is after a recordset
|
// the user is after a recordset
|
||||||
if ($plugin) {
|
$result = new stdClass;
|
||||||
$localcfg = $DB->get_records_menu('config_plugins', array('plugin'=>$plugin), '', 'name,value');
|
if (!$iscore) {
|
||||||
if (isset($CFG->forced_plugin_settings[$plugin])) {
|
$result = $DB->get_records_menu('config_plugins', array('plugin'=>$plugin), '', 'name,value');
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// this part is not really used any more, but anyway...
|
// this part is not really used any more, but anyway...
|
||||||
$localcfg = $DB->get_records_menu('config', array(), '', 'name,value');
|
$result = $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)) {
|
$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
|
// we do not want any extra mess here, just real settings that could be saved in db
|
||||||
unset($localcfg[$n]);
|
unset($result[$key]);
|
||||||
} else {
|
} else {
|
||||||
//convert to string as if it went through the DB
|
//convert to string as if it went through the DB
|
||||||
$localcfg[$n] = (string)$v;
|
$result[$key] = (string)$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (object)$localcfg;
|
|
||||||
}
|
return (object)$result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1418,8 +1411,10 @@ function unset_config($name, $plugin=NULL) {
|
||||||
if (empty($plugin)) {
|
if (empty($plugin)) {
|
||||||
unset($CFG->$name);
|
unset($CFG->$name);
|
||||||
$DB->delete_records('config', array('name'=>$name));
|
$DB->delete_records('config', array('name'=>$name));
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), 'core');
|
||||||
} else {
|
} else {
|
||||||
$DB->delete_records('config_plugins', array('name'=>$name, 'plugin'=>$plugin));
|
$DB->delete_records('config_plugins', array('name'=>$name, 'plugin'=>$plugin));
|
||||||
|
cache_helper::invalidate_by_definition('core', 'config', array(), $plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1433,10 +1428,15 @@ function unset_config($name, $plugin=NULL) {
|
||||||
*/
|
*/
|
||||||
function unset_all_config_for_plugin($plugin) {
|
function unset_all_config_for_plugin($plugin) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
// Delete from the obvious config_plugins first
|
||||||
$DB->delete_records('config_plugins', array('plugin' => $plugin));
|
$DB->delete_records('config_plugins', array('plugin' => $plugin));
|
||||||
|
// Next delete any suspect settings from config
|
||||||
$like = $DB->sql_like('name', '?', true, true, false, '|');
|
$like = $DB->sql_like('name', '?', true, true, false, '|');
|
||||||
$params = array($DB->sql_like_escape($plugin.'_', '|') . '%');
|
$params = array($DB->sql_like_escape($plugin.'_', '|') . '%');
|
||||||
$DB->delete_records_select('config', $like, $params);
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -713,7 +713,7 @@ function initialise_cfg() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($DB) {
|
if ($DB) {
|
||||||
$localcfg = $DB->get_records_menu('config', array(), '', 'name,value');
|
$localcfg = get_config('core');
|
||||||
foreach ($localcfg as $name => $value) {
|
foreach ($localcfg as $name => $value) {
|
||||||
if (property_exists($CFG, $name)) {
|
if (property_exists($CFG, $name)) {
|
||||||
// config.php settings always take precedence
|
// config.php settings always take precedence
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue