Skip to content

Commit

Permalink
MDL-30929 detect incorrect major version upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak authored and kordan committed Jan 19, 2012
1 parent 17f15e2 commit c122105
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@
$PAGE->set_pagelayout('maintenance');
$PAGE->set_popup_notification_allowed(false);

if (upgrade_stale_php_files_present()) {
$PAGE->set_title($stradministration);
$PAGE->set_cacheable(false);

$output = $PAGE->get_renderer('core', 'admin');
echo $output->upgrade_stale_php_files_page();
die();
}

if (empty($confirmupgrade)) {
$a->oldversion = "$CFG->release ($CFG->version)";
$a->newversion = "$release ($version)";
Expand Down
20 changes: 20 additions & 0 deletions admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ public function install_licence_page() {
return $output;
}

/**
* Display page explaining proper upgrade process,
* there can not be any PHP file leftovers...
*
* @return string HTML to output.
*/
public function upgrade_stale_php_files_page() {
$output = '';
$output .= $this->header();
$output .= $this->heading(get_string('upgradestalefiles', 'admin'));
$output .= $this->box_start('generalbox', 'notice');
$output .= get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading'));
$output .= html_writer::empty_tag('br');
$output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
$output .= $this->box_end();
$output .= $this->footer();

return $output;
}

/**
* Display the 'environment check' page that is displayed during install.
* @param int $maturity
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@
$string['upgradelogsinfo'] = 'Some changes have recently been made in the way logs are stored. To be able to view all of your old logs on a per-activity basis, your old logs need to be upgraded. Depending on your site this can take a long time (eg several hours) and can be quite taxing on the database for large sites. Once you start this process you should let it finish (by keeping the browser window open). Don\'t worry - your site will work fine for other people while the logs are being upgraded.<br /><br />Do you want to upgrade your logs now?';
$string['upgradesettings'] = 'New settings';
$string['upgradesettingsintro'] = 'The settings shown below were added during your last Moodle upgrade. Make any changes necessary to the defaults and then click the &quot;Save changes&quot; button at the bottom of this page.';
$string['upgradestalefiles'] = 'Invalid installation files detected, upgrade can not contine';
$string['upgradestalefilesinfo'] = 'Some old PHP scripts have been detected which may indicate that you installed this version over an older one. Please fix the installation directory by removing all old scripts (except config.php) before installing the new version and then try the upgrade again. You can find more information in upgrade documentation at <a href="{$a}">{$a}</a>';
$string['upgradesure'] = 'Your Moodle files have been changed, and you are about to automatically upgrade your server to this version: <br /><br />
<strong>{$a}</strong> <br /><br />
Once you do this you can not go back again. <br /><br />
Expand Down
35 changes: 35 additions & 0 deletions lib/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,41 @@ function upgrade_plugin_savepoint($result, $version, $type, $plugin, $allowabort
}
}

/**
* Detect if there are leftovers in PHP source files.
*
* During main version upgrades administrators MUST move away
* old PHP source files and start from scratch (or better
* use git).
*
* @return bool true means borked upgrade, false means previous PHP files were properly removed
*/
function upgrade_stale_php_files_present() {
global $CFG;

$someexamplesofremovedfiles = array(
// removed in 2.2dev
'/lib/yui/3.4.1pr1/',
// removed in 2.2
'/search/cron_php5.php',
'/course/report/log/indexlive.php',
'/admin/report/backups/index.php',
'/admin/generator.php',
// removed in 2.1
'/lib/yui/2.8.0r4/',
// removed in 2.0
'/blocks/admin/block_admin.php',
'/blocks/admin_tree/block_admin_tree.php',
);

foreach ($someexamplesofremovedfiles as $file) {
if (file_exists($CFG->dirroot.$file)) {
return true;
}
}

return false;
}

/**
* Upgrade plugins
Expand Down

0 comments on commit c122105

Please sign in to comment.