mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-47456-avoid-siteid-db' of https://github.com/brendanheywood/moodle
This commit is contained in:
commit
0c556aff71
@ -1457,8 +1457,6 @@ function set_config($name, $value, $plugin=null) {
|
||||
*
|
||||
* NOTE: this function is called from lib/db/upgrade.php
|
||||
*
|
||||
* @static string|false $siteidentifier The site identifier is not cached. We use this static cache so
|
||||
* that we need only fetch it once per request.
|
||||
* @param string $plugin full component name
|
||||
* @param string $name default null
|
||||
* @return mixed hash-like object or single value, return false no config found
|
||||
@ -1467,52 +1465,29 @@ function set_config($name, $value, $plugin=null) {
|
||||
function get_config($plugin, $name = null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
static $siteidentifier = null;
|
||||
|
||||
if ($plugin === 'moodle' || $plugin === 'core' || empty($plugin)) {
|
||||
$forced =& $CFG->config_php_settings;
|
||||
$iscore = true;
|
||||
$table = 'config';
|
||||
$filter = [];
|
||||
$plugin = 'core';
|
||||
} else {
|
||||
if (array_key_exists($plugin, $CFG->forced_plugin_settings)) {
|
||||
$forced =& $CFG->forced_plugin_settings[$plugin];
|
||||
} else {
|
||||
$forced = array();
|
||||
$forced = [];
|
||||
}
|
||||
$iscore = false;
|
||||
$table = 'config_plugins';
|
||||
$filter = ['plugin' => $plugin];
|
||||
}
|
||||
|
||||
if ($siteidentifier === null) {
|
||||
try {
|
||||
// This may fail during installation.
|
||||
// If you have a look at {@link initialise_cfg()} you will see that this is how we detect the need to
|
||||
// install the database.
|
||||
$siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier'));
|
||||
} catch (dml_exception $ex) {
|
||||
// Set siteidentifier to false. We don't want to trip this continually.
|
||||
$siteidentifier = false;
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
if (array_key_exists($name, $forced)) {
|
||||
return (string)$forced[$name];
|
||||
} else if ($name === 'siteidentifier' && $plugin == 'core') {
|
||||
return $siteidentifier;
|
||||
}
|
||||
if (!empty($name) && array_key_exists($name, $forced)) {
|
||||
return (string)$forced[$name];
|
||||
}
|
||||
|
||||
$cache = cache::make('core', 'config');
|
||||
$result = $cache->get($plugin);
|
||||
if ($result === false) {
|
||||
// The user is after a recordset.
|
||||
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');;
|
||||
}
|
||||
$result = $DB->get_records_menu($table, $filter, '', 'name,value');
|
||||
$cache->set($plugin, $result);
|
||||
}
|
||||
|
||||
@ -1523,10 +1498,6 @@ function get_config($plugin, $name = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($plugin === 'core') {
|
||||
$result['siteidentifier'] = $siteidentifier;
|
||||
}
|
||||
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user