diff --git a/admin/index.php b/admin/index.php index 237d7f430d2..4de2eaa622a 100644 --- a/admin/index.php +++ b/admin/index.php @@ -252,6 +252,9 @@ /// Check all enrolment plugins and upgrade if necessary upgrade_enrol_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards +/// Check for local database customisations + require_once("$CFG->dirroot/lib/locallib.php"); + upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards /// Set up the overall site name etc. diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 7525c28892c..2743c17f46d 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -248,6 +248,7 @@ $string['databasesetup'] = 'Setting up database'; $string['databasesuccess'] = 'Database was successfully upgraded'; $string['databaseupgradebackups'] = 'Backup version is now $a'; $string['databaseupgradeblocks'] = 'Blocks version is now $a'; +$string['databaseupgradelocal'] = 'Local database customisations version is now $a'; $string['databaseupgrades'] = 'Upgrading database'; $string['date'] = 'Date'; $string['datemostrecentfirst'] = 'Date - most recent first'; diff --git a/lib/locallib.php b/lib/locallib.php new file mode 100644 index 00000000000..06effafa198 --- /dev/null +++ b/lib/locallib.php @@ -0,0 +1,62 @@ +dbtype}.php + * + * To make it easier for people running custom moodles, it isn't necessary to have {$CFG->dbtype}.sql + * as well. Rather than detecting the difference between install and upgrade, + * and looking for {$CFG->dbtype}.php or {$CFG->type}.sql accordingly, + * the upgrade_local_db function will just start from 0 if it hasn't been run before, + * effectively playing all upgrades in {$CFG->dbtype}.php +*/ + + +function upgrade_local_db($continueto) { + + global $CFG, $db; + + // if we don't have code version or a db upgrade file, just return true, we're unneeded + if (!file_exists($CFG->dirroot.'/local/version.php') || !file_exists($CFG->dirroot.'/local/db/'.$CFG->dbtype.'.php')) { + return true; + } + + require_once ($CFG->dirroot .'/local/version.php'); // Get code versions + + if (empty($CFG->local_version)) { // normally we'd install, but just replay all the upgrades. + $CFG->local_version = 0; + } + + if ($local_version > $CFG->local_version) { // upgrade! + $strdatabaseupgrades = get_string('databaseupgrades'); + print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades); + + require_once ($CFG->dirroot .'/local/db/'. $CFG->dbtype .'.php'); + + $db->debug=true; + if (local_upgrade($CFG->local_version)) { + $db->debug=false; + if (set_config('local_version', $local_version)) { + notify(get_string('databasesuccess'), 'notifysuccess'); + notify(get_string('databaseupgradelocal', '', $local_version)); + print_continue($continueto); + exit; + } else { + error('Upgrade of local database customisations failed! (Could not update version in config table)'); + } + } else { + $db->debug=false; + error('Upgrade failed! See local/version.php'); + } + + } else if ($local_version < $CFG->local_version) { + notify('WARNING!!! The local version you are using is OLDER than the version that made these databases!'); + } +} + + +?> \ No newline at end of file