Skip to content

Commit

Permalink
Merge branch 'w17_MDL-39343_m25_installupgrade' of git://github.com/s…
Browse files Browse the repository at this point in the history
…kodak/moodle
  • Loading branch information
danpoltawski committed Apr 30, 2013
2 parents 8926c9f + e2e35e7 commit 0542fdc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion admin/cli/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
/** 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
Expand Down
1 change: 1 addition & 0 deletions admin/cli/install_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
1 change: 1 addition & 0 deletions admin/cli/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@

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
Expand All @@ -60,21 +67,28 @@
$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));
}
Expand Down Expand Up @@ -199,6 +213,14 @@
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();

Expand Down Expand Up @@ -412,6 +434,12 @@
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();
Expand Down Expand Up @@ -498,7 +526,7 @@
if ($fetchupdates) {
require_sesskey();
$updateschecker->fetch();
redirect($PAGE->url);
redirect(new moodle_url('/admin/index.php'));
}

$output = $PAGE->get_renderer('core', 'admin');
Expand Down
3 changes: 2 additions & 1 deletion admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ protected function available_updates($updates, $fetch) {
}

$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'))));
Expand Down
14 changes: 13 additions & 1 deletion lib/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0542fdc

Please sign in to comment.