Skip to content

Commit

Permalink
MDL-42973 fix multiple addon update issues
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 6, 2013
1 parent c36a240 commit fc28111
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 134 deletions.
108 changes: 61 additions & 47 deletions admin/index.php
Expand Up @@ -47,7 +47,9 @@

define('NO_OUTPUT_BUFFERING', true);

if (empty($_GET['cache']) and empty($_POST['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey'])) {
if ((isset($_GET['cache']) and $_GET['cache'] === '0')
or (isset($_POST['cache']) and $_POST['cache'] === '0')
or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) {
// 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.
Expand Down Expand Up @@ -90,9 +92,7 @@

// Set up PAGE.
$url = new moodle_url('/admin/index.php');
if ($cache) {
$url->param('cache', 1);
}
$url->param('cache', $cache);
$PAGE->set_url($url);
unset($url);

Expand Down Expand Up @@ -267,12 +267,13 @@
$PAGE->set_pagelayout('maintenance');
$PAGE->set_popup_notification_allowed(false);

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

if (upgrade_stale_php_files_present()) {
$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 @@ -287,8 +288,6 @@
$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, $testsite);
die();

Expand All @@ -302,8 +301,6 @@
$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 @@ -315,23 +312,13 @@
$PAGE->set_heading($strplugincheck);
$PAGE->set_cacheable(false);

$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 (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl);
die();
}
unset($failed);
$reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0));

if ($fetchupdates) {
// no sesskey support guaranteed here
if (empty($CFG->disableupdatenotifications)) {
\core\update\checker::instance()->fetch();
// No sesskey support guaranteed here, because sessions might not work yet.
$updateschecker = \core\update\checker::instance();
if ($updateschecker->enabled()) {
$updateschecker->fetch();
}
redirect($reloadurl);
}
Expand All @@ -342,18 +329,30 @@

$deploydata = $deployer->submitted_data();
if (!empty($deploydata)) {
// No sesskey support guaranteed here, because sessions might not work yet.
echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
die();
}
}

echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(),
$version, $showallplugins, $reloadurl,
new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)));
new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1, 'cache'=>0)));
die();

} else {
// Launch main upgrade
// Always verify plugin dependencies!
$failed = array();
if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
$PAGE->set_pagelayout('maintenance');
$PAGE->set_popup_notification_allowed(false);
$reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0));
echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl);
die();
}
unset($failed);

// Launch main upgrade.
upgrade_core($version, true);
}
} else if ($version < $CFG->version) {
Expand All @@ -373,6 +372,10 @@
if (!$cache and moodle_needs_upgrading()) {
if (!$PAGE->headerprinted) {
// means core upgrade or installation was not already done

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

if (!$confirmplugins) {
$strplugincheck = get_string('plugincheck');

Expand All @@ -384,40 +387,46 @@
$PAGE->set_cacheable(false);

if ($fetchupdates) {
// no sesskey support guaranteed here
\core\update\checker::instance()->fetch();
require_sesskey();
$updateschecker = \core\update\checker::instance();
if ($updateschecker->enabled()) {
$updateschecker->fetch();
}
redirect($PAGE->url);
}

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

$deployer = \core\update\deployer::instance();
if ($deployer->enabled()) {
$deployer->initialize($PAGE->url, $PAGE->url);

$deploydata = $deployer->submitted_data();
if (!empty($deploydata)) {
require_sesskey();
echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
die();
}
}

// check plugin dependencies first
$failed = array();
if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url);
die();
}
unset($failed);

// dependencies check passed, let's rock!
// Show plugins info.
echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(),
$version, $showallplugins,
new moodle_url($PAGE->url),
new moodle_url('/admin/index.php', array('confirmplugincheck'=>1)));
new moodle_url('/admin/index.php', array('confirmplugincheck'=>1, 'cache'=>0)));
die();
}

// Make sure plugin dependencies are always checked.
$failed = array();
if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
$PAGE->set_pagelayout('maintenance');
$PAGE->set_popup_notification_allowed(false);
$reloadurl = new moodle_url('/admin/index.php', array('cache' => 0));
echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl);
die();
}
unset($failed);
}

// install/upgrade all plugins and other parts
upgrade_noncore(true);
}
Expand Down Expand Up @@ -477,6 +486,17 @@
upgrade_finished('upgradesettings.php');
}

if (has_capability('moodle/site:config', context_system::instance())) {
if ($fetchupdates) {
require_sesskey();
$updateschecker = \core\update\checker::instance();
if ($updateschecker->enabled()) {
$updateschecker->fetch();
}
redirect(new moodle_url('/admin/index.php', array('cache' => 0)));
}
}

// Now we can be sure everything was upgraded and caches work fine,
// redirect if necessary to make sure caching is enabled.
if (!$cache) {
Expand Down Expand Up @@ -564,12 +584,6 @@

admin_externalpage_setup('adminnotifications');

if ($fetchupdates) {
require_sesskey();
$updateschecker->fetch();
redirect(new moodle_url('/admin/index.php'));
}

$output = $PAGE->get_renderer('core', 'admin');
echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
$cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
Expand Down
14 changes: 7 additions & 7 deletions admin/renderer.php
Expand Up @@ -140,7 +140,7 @@ public function unsatisfied_dependencies_page($version, array $failed, moodle_ur
public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
$output = '';

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

Expand Down Expand Up @@ -170,7 +170,7 @@ public function upgrade_environment_page($release, $envstatus, $environment_resu
$output .= $this->environment_check_table($envstatus, $environment_results);

if (!$envstatus) {
$output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
$output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1, 'cache' => 0));

} else {
$output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
Expand All @@ -179,7 +179,7 @@ public function upgrade_environment_page($release, $envstatus, $environment_resu
$output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
}

$output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
$output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
}

$output .= $this->footer();
Expand Down Expand Up @@ -711,7 +711,7 @@ protected function available_updates($updates, $fetch) {
}

$updateinfo .= $this->container_start('checkforupdates');
$fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 1));
$fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
$updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
if ($fetch) {
$updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
Expand Down Expand Up @@ -962,7 +962,7 @@ public function plugins_check_table(core_plugin_manager $pluginman, $version, ar
$out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
if (empty($options['full'])) {
$out .= html_writer::link(new moodle_url('/admin/index.php',
array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
get_string('nonehighlightedinfo', 'core_plugin'));
}
$out .= $this->output->container_end();
Expand All @@ -972,11 +972,11 @@ public function plugins_check_table(core_plugin_manager $pluginman, $version, ar
$out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
if (empty($options['full'])) {
$out .= html_writer::link(new moodle_url('/admin/index.php',
array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
get_string('somehighlightedinfo', 'core_plugin'));
} else {
$out .= html_writer::link(new moodle_url('/admin/index.php',
array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0, 'cache' => 0)),
get_string('somehighlightedonly', 'core_plugin'));
}
$out .= $this->output->container_end();
Expand Down
12 changes: 12 additions & 0 deletions lib/classes/update/checker.php
Expand Up @@ -81,6 +81,18 @@ public static function reset_caches($phpunitreset = false) {
}
}

/**
* Is automatic deployment enabled?
*
* @return bool
*/
public function enabled() {
global $CFG;

// The feature can be prohibited via config.php.
return empty($CFG->disableupdateautodeploy);
}

/**
* Returns the timestamp of the last execution of {@link fetch()}
*
Expand Down

0 comments on commit fc28111

Please sign in to comment.