From 392e73631e4d31b5186c0d4c452d5f522b103611 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 23 Dec 2007 13:10:35 +0000 Subject: [PATCH] MDL-12716 fixed admin setting for rcache; more robust rcache handling in setup.php; merged from MOODLE_19_STABLE --- admin/settings/server.php | 4 ++-- lib/adminlib.php | 20 +++++++++++++++++++- lib/setup.php | 30 ++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/admin/settings/server.php b/admin/settings/server.php index 3dc8ba43e2..4f7e336a1c 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -207,14 +207,14 @@ $ADMIN->add('server', new admin_externalpage('phpinfo', get_string('phpinfo'), " // "performance" settingpage $temp = new admin_settingpage('performance', get_string('performance', 'admin')); -$temp->add(new admin_setting_configselect('cachetype', get_string('cachetype', 'admin'), +$temp->add(new admin_setting_special_selectsetup('cachetype', get_string('cachetype', 'admin'), get_string('configcachetype', 'admin'), '', array( '' => get_string('none'), 'internal' => 'internal', 'memcached' => 'memcached', 'eaccelerator' => 'eaccelerator'))); // NOTE: $CFG->rcache is forced to bool in lib/setup.php -$temp->add(new admin_setting_configselect('rcache', get_string('rcache', 'admin'), +$temp->add(new admin_setting_special_selectsetup('rcache', get_string('rcache', 'admin'), get_string('configrcache', 'admin'), 0, array( '0' => get_string('no'), '1' => get_string('yes')))); diff --git a/lib/adminlib.php b/lib/adminlib.php index f2c7b77449..6209cd82d7 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2382,6 +2382,25 @@ class admin_setting_special_adminseesall extends admin_setting_configcheckbox { } } +/** + * Special select for settings that are altered in setup.php and can not be altered on the fly + */ +class admin_setting_special_selectsetup extends admin_setting_configselect { + function get_setting() { + // read directly from db! + return get_config(NULL, $this->name); + } + + function write_setting($data) { + global $CFG; + // do not change active CFG setting! + $current = $CFG->{$this->name}; + $result = parent::write_setting($data); + $CFG->{$this->name} = $current; + return $result; + } +} + /** * Special select for frontpage - stores data in course table */ @@ -2402,7 +2421,6 @@ class admin_setting_sitesetselect extends admin_setting_configselect { $record->timemodified = time(); return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin')); } - } /** diff --git a/lib/setup.php b/lib/setup.php index ca392352b8..65f20e36d0 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -283,25 +283,39 @@ global $HTTPSPAGEREQUIRED; /// Shared-Memory cache init -- will set $MCACHE /// $MCACHE is a global object that offers at least add(), set() and delete() /// with similar semantics to the memcached PHP API http://php.net/memcache +/// Ensure we define rcache - so we can later check for it +/// with a really fast and unambiguous $CFG->rcache === false if (!empty($CFG->cachetype)) { + if (array_key_exists('rcache', $CFG->config_php_settings)) { + $CFG->rcache = (bool)$CFG->config_php_settings['rcache']; // always use config.php setting if present + } else if (empty($CFG->rcache)) { + $CFG->rcache = false; + } else { + $CFG->rcache = true; + } + + // do not try to initialize if cache disabled + if (!$CFG->rcache) { + $CFG->cachetype = ''; + } + if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) { if (!init_memcached()) { debugging("Error initialising memcached"); } - } elseif ($CFG->cachetype === 'eaccelerator') { + $CFG->cachetype = ''; + $CFG->rcache = false; + } else if ($CFG->cachetype === 'eaccelerator') { if (!init_eaccelerator()) { debugging("Error initialising eaccelerator cache"); } + $CFG->cachetype = ''; + $CFG->rcache = false; } + } else { // just make sure it is defined $CFG->cachetype = ''; - } -/// Ensure we define rcache - so we can later check for it -/// with a really fast and unambiguous $CFG->rcache === false - if (empty($CFG->rcache)) { - $CFG->rcache = false; - } else { - $CFG->rcache = true; + $CFG->rcache = false; } /// Set a default enrolment configuration (see bug 1598) -- 2.39.5