Skip to content

Commit

Permalink
MDL-41245 fix multiple install, upgrade and uninstallation issues
Browse files Browse the repository at this point in the history
Includes rework of cache parameter detection on admin/index.php.

Another problem is that uninstall does not leave system in consistent state,
we need to force users to go through upgrade after any type of uninstall.

This fixes also add-on installation redirect and other issues.
  • Loading branch information
skodak committed Aug 24, 2013
1 parent d2aa53b commit 82b1cf0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 39 deletions.
68 changes: 35 additions & 33 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
if (function_exists('opcache_reset')) {
opcache_reset();
}
$cache = 0;

} else {
$cache = 1;
}

require('../config.php');
Expand All @@ -74,22 +78,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);

// 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.
$url->param('installaddonrequest', $newaddonreq);
}
if ($cache) {
$url->param('cache', $cache);
$url->param('cache', 1);
}
$PAGE->set_url($url);
unset($url);

// Are we returning from an add-on installation request at moodle.org/plugins?
if (!$cache and empty($CFG->disableonclickaddoninstall)) {
$target = new moodle_url('/admin/tool/installaddon/index.php', array(
'installaddonrequest' => $newaddonreq,
'confirm' => 0));
if (!isloggedin() or isguestuser()) {
// Login and go the the add-on tool page.
$SESSION->wantsurl = $target->out();
redirect(get_login_url());
}
redirect($target);
}

$PAGE->set_pagelayout('admin'); // Set a default pagelayout

$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
Expand Down Expand Up @@ -153,6 +163,7 @@
$PAGE->set_heading($strinstallation);
$PAGE->set_cacheable(false);

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');
echo $output->install_licence_page();
die();
Expand All @@ -167,6 +178,7 @@
$PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
$PAGE->set_cacheable(false);

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');
echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release);
die();
Expand Down Expand Up @@ -221,14 +233,12 @@
}

// 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 ($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
if (!$cache and $version > $CFG->version) { // upgrade
// We purge all of MUC's caches here.
// Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
// This ensures a real config object is loaded and the stores will be purged.
Expand All @@ -245,6 +255,7 @@
$PAGE->set_title($stradministration);
$PAGE->set_cacheable(false);

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');
echo $output->upgrade_stale_php_files_page();
die();
Expand All @@ -260,6 +271,7 @@
$PAGE->set_heading($strdatabasechecking);
$PAGE->set_cacheable(false);

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');
echo $output->upgrade_confirm_page($a->newversion, $maturity);
die();
Expand All @@ -274,6 +286,7 @@
$PAGE->set_heading($strcurrentrelease);
$PAGE->set_cacheable(false);

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');
echo $output->upgrade_environment_page($release, $envstatus, $environment_results);
die();
Expand All @@ -288,10 +301,12 @@

$reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1));

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');

// check plugin dependencies first
$failed = array();
if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) {
$output = $PAGE->get_renderer('core', 'admin');
echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl);
die();
}
Expand All @@ -305,8 +320,6 @@
redirect($reloadurl);
}

$output = $PAGE->get_renderer('core', 'admin');

$deployer = available_update_deployer::instance();
if ($deployer->enabled()) {
$deployer->initialize($reloadurl, $reloadurl);
Expand All @@ -333,15 +346,15 @@
}

// Updated human-readable release version if necessary
if ($release <> $CFG->release) { // Update the release version
if (!$cache and $release <> $CFG->release) { // Update the release version
set_config('release', $release);
}

if ($branch <> $CFG->branch) { // Update the branch
if (!$cache and $branch <> $CFG->branch) { // Update the branch
set_config('branch', $branch);
}

if (moodle_needs_upgrading()) {
if (!$cache and moodle_needs_upgrading()) {
if (!$PAGE->headerprinted) {
// means core upgrade or installation was not already done
if (!$confirmplugins) {
Expand Down Expand Up @@ -450,8 +463,8 @@

// Now we can be sure everything was upgraded and caches work fine,
// redirect if necessary to make sure caching is enabled.
if (!$cache and !optional_param('sesskey', '', PARAM_RAW)) {
redirect(new moodle_url($PAGE->url, array('cache' => 1)));
if (!$cache) {
redirect(new moodle_url('/admin/index.php', array('cache' => 1)));
}

// Check for valid admin user - no guest autologin
Expand All @@ -473,17 +486,6 @@
set_config('registered', time());
}

// Check if we are returning from an add-on installation request at moodle.org/plugins
if (!is_null($newaddonreq)) {
if (!empty($CFG->disableonclickaddoninstall)) {
// The feature is disabled in config.php, ignore the request.
} else {
redirect(new moodle_url('/admin/tool/installaddon/index.php', array(
'installaddonrequest' => $newaddonreq,
'confirm' => 0)));
}
}

// setup critical warnings before printing admin tree block
$insecuredataroot = is_dataroot_insecure(true);
$SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
Expand Down
4 changes: 3 additions & 1 deletion admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
$delete = optional_param('delete', '', PARAM_COMPONENT);
$confirmed = optional_param('confirm', false, PARAM_BOOL);

/** @var core_admin_renderer $output */
$output = $PAGE->get_renderer('core', 'admin');

$pluginman = plugin_manager::instance();
Expand Down Expand Up @@ -143,7 +144,8 @@
if (function_exists('opcache_reset')) {
opcache_reset();
}
redirect($PAGE->url);
// We need to execute upgrade to make sure everything including caches is up to date.
redirect(new moodle_url('/admin/index.php'));
}

$checker = available_update_checker::instance();
Expand Down
16 changes: 11 additions & 5 deletions admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ public function unsatisfied_dependencies_page($version, array $failed, moodle_ur
public function upgrade_confirm_page($strnewversion, $maturity) {
$output = '';

$continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
$cancelurl = new moodle_url('index.php');
$continueurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1));
$continue = new single_button($continueurl, get_string('continue'), 'get');
$cancelurl = new moodle_url('/admin/index.php');

$output .= $this->header();
$output .= $this->maturity_warning($maturity);
$output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
$output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
$output .= $this->footer();

return $output;
Expand Down Expand Up @@ -412,6 +413,10 @@ public function plugin_uninstall_results_removable_page(plugin_manager $pluginma

$pluginname = $pluginman->plugin_name($pluginfo->component);

// Do not show navigation here, they must click one of the buttons.
$this->page->set_pagelayout('maintenance');
$this->page->set_cacheable(false);

$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));

Expand All @@ -425,7 +430,8 @@ public function plugin_uninstall_results_removable_page(plugin_manager $pluginma
'uninstalldeleteconfirmexternal');
}

$output .= $this->output->confirm($confirm, $continueurl, $this->page->url);
// After any uninstall we must execute full upgrade to finish the cleanup!
$output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
$output .= $this->output->footer();

return $output;
Expand Down Expand Up @@ -708,7 +714,7 @@ protected function registration_warning($registered) {

if (!$registered) {

$registerbutton = $this->single_button(new moodle_url('registration/register.php',
$registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
get_string('register', 'admin'));

Expand Down
3 changes: 3 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ function uninstall_plugin($type, $name) {
// Finally purge all caches.
purge_all_caches();

// Invalidate the hash used for upgrade detections.
set_config('allversionshash', '');

echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}

Expand Down

0 comments on commit 82b1cf0

Please sign in to comment.