diff --git a/admin/cli/install.php b/admin/cli/install.php index 35db018fd7f..8ea69e35c42 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -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 diff --git a/admin/cli/install_database.php b/admin/cli/install_database.php index 27a38aab42c..dfc7a420d8a 100644 --- a/admin/cli/install_database.php +++ b/admin/cli/install_database.php @@ -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'])) { diff --git a/admin/cli/upgrade.php b/admin/cli/upgrade.php index 72a03f0b075..a6b36ba7251 100644 --- a/admin/cli/upgrade.php +++ b/admin/cli/upgrade.php @@ -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 diff --git a/admin/index.php b/admin/index.php index 9c1a9132400..329c79b6463 100644 --- a/admin/index.php +++ b/admin/index.php @@ -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 = 'Installation docs'; +// 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'); diff --git a/admin/renderer.php b/admin/renderer.php index 9f53ead23b7..e70815296a6 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -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')))); diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 649c282dfc3..ec59a74f553 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -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