From 82b1cf00b0f246a6a8b06c188b91b8a24a24003d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Fri, 16 Aug 2013 11:02:03 +0200 Subject: [PATCH] MDL-41245 fix multiple install, upgrade and uninstallation issues 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. --- admin/index.php | 68 ++++++++++++++++++++++++---------------------- admin/plugins.php | 4 ++- admin/renderer.php | 16 +++++++---- lib/adminlib.php | 3 ++ 4 files changed, 52 insertions(+), 39 deletions(-) diff --git a/admin/index.php b/admin/index.php index 1e9e810aa91..2d666d51dc7 100644 --- a/admin/index.php +++ b/admin/index.php @@ -59,6 +59,10 @@ if (empty($_GET['cache']) and empty($_POST['cache']) and empty($_GET['sesskey']) if (function_exists('opcache_reset')) { opcache_reset(); } + $cache = 0; + +} else { + $cache = 1; } require('../config.php'); @@ -74,22 +78,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); // 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 = 'Installation docs'; @@ -153,6 +163,7 @@ if (!core_tables_exist()) { $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(); @@ -167,6 +178,7 @@ if (!core_tables_exist()) { $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(); @@ -221,14 +233,12 @@ if (empty($CFG->version)) { } // 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. @@ -245,6 +255,7 @@ if ($version > $CFG->version) { // upgrade $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(); @@ -260,6 +271,7 @@ if ($version > $CFG->version) { // upgrade $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(); @@ -274,6 +286,7 @@ if ($version > $CFG->version) { // upgrade $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(); @@ -288,10 +301,12 @@ if ($version > $CFG->version) { // upgrade $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(); } @@ -305,8 +320,6 @@ if ($version > $CFG->version) { // upgrade redirect($reloadurl); } - $output = $PAGE->get_renderer('core', 'admin'); - $deployer = available_update_deployer::instance(); if ($deployer->enabled()) { $deployer->initialize($reloadurl, $reloadurl); @@ -333,15 +346,15 @@ if ($version > $CFG->version) { // upgrade } // 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) { @@ -450,8 +463,8 @@ if (during_initial_install()) { // 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 @@ -473,17 +486,6 @@ if (!empty($id) and $id == $CFG->siteidentifier) { 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); diff --git a/admin/plugins.php b/admin/plugins.php index 8ceba12c755..d0788b6593d 100644 --- a/admin/plugins.php +++ b/admin/plugins.php @@ -48,6 +48,7 @@ $uninstall = optional_param('uninstall', '', PARAM_COMPONENT); $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(); @@ -143,7 +144,8 @@ if ($delete and $confirmed) { 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(); diff --git a/admin/renderer.php b/admin/renderer.php index 68cdb49bcef..ffccc33d56e 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -140,12 +140,13 @@ class core_admin_renderer extends plugin_renderer_base { 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; @@ -412,6 +413,10 @@ class core_admin_renderer extends plugin_renderer_base { $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))); @@ -425,7 +430,8 @@ class core_admin_renderer extends plugin_renderer_base { '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; @@ -708,7 +714,7 @@ class core_admin_renderer extends plugin_renderer_base { 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')); diff --git a/lib/adminlib.php b/lib/adminlib.php index 5d209bda3a2..9359ab82ff1 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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'); }