diff --git a/admin/index.php b/admin/index.php
index b4bcff75173..7e8a6fc0f40 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -190,6 +190,15 @@ if ($version > $CFG->version) { // upgrade
$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)";
diff --git a/admin/renderer.php b/admin/renderer.php
index f0aae313da7..014295008e3 100644
--- a/admin/renderer.php
+++ b/admin/renderer.php
@@ -57,6 +57,26 @@ class core_admin_renderer extends plugin_renderer_base {
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
diff --git a/lang/en/admin.php b/lang/en/admin.php
index eae32f878b2..876b3903494 100644
--- a/lang/en/admin.php
+++ b/lang/en/admin.php
@@ -971,6 +971,8 @@ $string['upgradelogs'] = 'For full functionality, your old logs need to be upgra
$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.
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 "Save changes" 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}';
$string['upgradesure'] = 'Your Moodle files have been changed, and you are about to automatically upgrade your server to this version:
{$a}
Once you do this you can not go back again.
diff --git a/lib/upgradelib.php b/lib/upgradelib.php
index b2db2b8be6f..6fed9b10e16 100644
--- a/lib/upgradelib.php
+++ b/lib/upgradelib.php
@@ -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