MDL-39343 disable all caching in install and upgrades

This should resolve all problem on developer machines when switching branches or when restoring previous Moodle databases. It also prevents any potential problems during upgrades such as concurrent DB modification and resolves chicken egg problems in future caching upgrades.
This commit is contained in:
Petr Škoda 2013-04-27 21:54:06 +02:00
parent cf5a3296c4
commit e2e35e71f9
6 changed files with 53 additions and 10 deletions

View file

@ -127,7 +127,7 @@ if (function_exists('date_default_timezone_set') and function_exists('date_defau
/** Used by library scripts to check they are being called by Moodle */
define('MOODLE_INTERNAL', true);
// Disables caching.. just in case.
// Disables all caching.
define('CACHE_DISABLE_ALL', true);
// Check that PHP is of a sufficient version

View file

@ -29,6 +29,7 @@
*/
define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true);
// extra execution prevention - we can not just require config.php here
if (isset($_SERVER['REMOTE_ADDR'])) {

View file

@ -30,6 +30,7 @@
*/
define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions

View file

@ -47,6 +47,13 @@ if (!function_exists('iconv')) {
define('NO_OUTPUT_BUFFERING', true);
if (empty($_GET['cache']) and empty($_POST['cache'])) {
// Prevent caching at all cost when visiting this page directly,
// we redirect to self once we known no upgrades are necessary.
// Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet.
define('CACHE_DISABLE_ALL', true);
}
require('../config.php');
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
@ -60,21 +67,28 @@ $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL);
$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
$fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL);
$newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW);
$cache = optional_param('cache', 0, PARAM_BOOL);
// Check some PHP server settings
if (is_null($newaddonreq)) {
$PAGE->set_url('/admin/index.php');
} else {
// Set up PAGE.
$url = new moodle_url('/admin/index.php');
if (!is_null($newaddonreq)) {
// We need to set the eventual add-on installation request in the $PAGE's URL
// so that it is stored in $SESSION->wantsurl and the admin is redirected
// correctly once they are logged-in.
$PAGE->set_url('/admin/index.php', array('installaddonrequest' => $newaddonreq));
$url->param('installaddonrequest', $newaddonreq);
}
if ($cache) {
$url->param('cache', $cache);
}
$PAGE->set_url($url);
unset($url);
$PAGE->set_pagelayout('admin'); // Set a default pagelayout
$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
// Check some PHP server settings
if (ini_get_bool('session.auto_start')) {
print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
}
@ -199,6 +213,14 @@ if (empty($CFG->version)) {
print_error('missingconfigversion', 'debug');
}
// Detect config cache inconsistency, this happens when you switch branches on dev servers.
if ($cache) {
if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) {
purge_all_caches();
redirect(new moodle_url('/admin/index.php'), 'Config cache inconsistency detected, resetting caches...');
}
}
if ($version > $CFG->version) { // upgrade
purge_all_caches();
@ -412,6 +434,12 @@ if (during_initial_install()) {
upgrade_finished('upgradesettings.php');
}
// Now we can be sure everything was upgraded and caches work fine,
// redirect if necessary to make sure caching is enabled.
if (!$cache) {
redirect(new moodle_url($PAGE->url, array('cache' => 1)));
}
// Check for valid admin user - no guest autologin
require_login(0, false);
$context = context_system::instance();
@ -498,7 +526,7 @@ admin_externalpage_setup('adminnotifications');
if ($fetchupdates) {
require_sesskey();
$updateschecker->fetch();
redirect($PAGE->url);
redirect(new moodle_url('/admin/index.php'));
}
$output = $PAGE->get_renderer('core', 'admin');

View file

@ -681,7 +681,8 @@ class core_admin_renderer extends plugin_renderer_base {
}
$updateinfo .= $this->container_start('checkforupdates');
$updateinfo .= $this->single_button(new moodle_url($this->page->url, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
$fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 1));
$updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
if ($fetch) {
$updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));

View file

@ -1458,6 +1458,14 @@ function upgrade_language_pack($lang = null) {
function install_core($version, $verbose) {
global $CFG, $DB;
// We can not call purge_all_caches() yet, make sure the temp and cache dirs exist and are empty.
make_cache_directory('', true);
remove_dir($CFG->cachedir.'', true);
make_temp_directory('', true);
remove_dir($CFG->tempdir.'', true);
make_writable_directory($CFG->dataroot.'/muc', true);
remove_dir($CFG->dataroot.'/muc', true);
try {
// Disable the use of cache stores here. We will reset the factory after we've performed the installation.
// This ensures that we don't permanently cache anything during installation.
@ -1591,12 +1599,16 @@ function upgrade_noncore($verbose) {
/**
* Checks if the main tables have been installed yet or not.
*
* Note: we can not use caches here because they might be stale,
* use with care!
*
* @return bool
*/
function core_tables_exist() {
global $DB;
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
if (!$tables = $DB->get_tables(false) ) { // No tables yet at all.
return false;
} else { // Check for missing main tables