Merge branch 'wip-MDL-34344-m25' of git://github.com/samhemelryk/moodle
Conflicts: lib/db/caches.php
This commit is contained in:
@@ -150,6 +150,8 @@ class block_section_links extends block_base {
|
||||
global $DB;
|
||||
// TODO: Move these config settings to proper ones using component name
|
||||
$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() {
|
||||
|
||||
@@ -34,6 +34,7 @@ $string['area'] = 'Area';
|
||||
$string['caching'] = 'Caching';
|
||||
$string['cacheadmin'] = 'Cache administration';
|
||||
$string['cacheconfig'] = 'Configuration';
|
||||
$string['cachedef_config'] = 'Config settings';
|
||||
$string['cachedef_databasemeta'] = 'Database meta information';
|
||||
$string['cachedef_eventinvalidation'] = 'Event invalidation';
|
||||
$string['cachedef_htmlpurifier'] = 'HTML Purifier - cleaned content';
|
||||
|
||||
+12
-1
@@ -82,5 +82,16 @@ $definitions = array(
|
||||
// cleaned text which is shareable.
|
||||
'htmlpurifier' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
)
|
||||
),
|
||||
|
||||
// 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_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}_%"));
|
||||
cache_helper::invalidate_by_definition('core', 'config', array(), 'message');
|
||||
}
|
||||
|
||||
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('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_{$component}_%"));
|
||||
$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
|
||||
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("{$name}_provider_%"));
|
||||
$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}"));
|
||||
}
|
||||
|
||||
+55
-55
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -713,8 +713,8 @@ function initialise_cfg() {
|
||||
|
||||
try {
|
||||
if ($DB) {
|
||||
$localcfg = $DB->get_records_menu('config', array(), '', 'name,value');
|
||||
foreach ($localcfg as $name=>$value) {
|
||||
$localcfg = get_config('core');
|
||||
foreach ($localcfg as $name => $value) {
|
||||
if (property_exists($CFG, $name)) {
|
||||
// config.php settings always take precedence
|
||||
continue;
|
||||
|
||||
@@ -2144,4 +2144,56 @@ class moodlelib_testcase extends advanced_testcase {
|
||||
date_default_timezone_set($systemdefaulttimezone);
|
||||
setlocale(LC_TIME, $oldlocale);
|
||||
}
|
||||
|
||||
public function test_get_config() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Preparation.
|
||||
set_config('phpunit_test_get_config_1', 'test 1');
|
||||
set_config('phpunit_test_get_config_2', 'test 2', 'mod_forum');
|
||||
if (!is_array($CFG->config_php_settings)) {
|
||||
$CFG->config_php_settings = array();
|
||||
}
|
||||
$CFG->config_php_settings['phpunit_test_get_config_3'] = 'test 3';
|
||||
|
||||
if (!is_array($CFG->forced_plugin_settings)) {
|
||||
$CFG->forced_plugin_settings = array();
|
||||
}
|
||||
if (!array_key_exists('mod_forum', $CFG->forced_plugin_settings)) {
|
||||
$CFG->forced_plugin_settings['mod_forum'] = array();
|
||||
}
|
||||
$CFG->forced_plugin_settings['mod_forum']['phpunit_test_get_config_4'] = 'test 4';
|
||||
$CFG->phpunit_test_get_config_5 = 'test 5';
|
||||
|
||||
// Testing.
|
||||
$this->assertEquals('test 1', get_config('core', 'phpunit_test_get_config_1'));
|
||||
$this->assertEquals('test 2', get_config('mod_forum', 'phpunit_test_get_config_2'));
|
||||
$this->assertEquals('test 3', get_config('core', 'phpunit_test_get_config_3'));
|
||||
$this->assertEquals('test 4', get_config('mod_forum', 'phpunit_test_get_config_4'));
|
||||
$this->assertFalse(get_config('core', 'phpunit_test_get_config_5'));
|
||||
$this->assertFalse(get_config('core', 'phpunit_test_get_config_x'));
|
||||
$this->assertFalse(get_config('mod_forum', 'phpunit_test_get_config_x'));
|
||||
|
||||
// Test config we know to exist.
|
||||
$this->assertEquals($CFG->dataroot, get_config('core', 'dataroot'));
|
||||
$this->assertEquals($CFG->phpunit_dataroot, get_config('core', 'phpunit_dataroot'));
|
||||
$this->assertEquals($CFG->dataroot, get_config('core', 'phpunit_dataroot'));
|
||||
$this->assertEquals(get_config('core', 'dataroot'), get_config('core', 'phpunit_dataroot'));
|
||||
|
||||
// Test setting a config var that already exists.
|
||||
set_config('phpunit_test_get_config_1', 'test a');
|
||||
$this->assertEquals('test a', $CFG->phpunit_test_get_config_1);
|
||||
$this->assertEquals('test a', get_config('core', 'phpunit_test_get_config_1'));
|
||||
|
||||
// Test cache invalidation.
|
||||
$cache = cache::make('core', 'config');
|
||||
$this->assertInternalType('array', $cache->get('core'));
|
||||
$this->assertInternalType('array', $cache->get('mod_forum'));
|
||||
set_config('phpunit_test_get_config_1', 'test b');
|
||||
$this->assertFalse($cache->get('core'));
|
||||
set_config('phpunit_test_get_config_4', 'test c', 'mod_forum');
|
||||
$this->assertFalse($cache->get('mod_forum'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user