Browse files

Added locallib - hook to provide easier means for local customisation…

…s. Currently contains mechanism for having local db upgrades without munging the main CFG->dbtype.php scripts.
  • Loading branch information...
1 parent 3317472 commit 43e664cca716007105b95d3bfc68f283f5d170a4 mjollnir_ committed Aug 15, 2005
Showing with 66 additions and 0 deletions.
  1. +3 −0 admin/index.php
  2. +1 −0 lang/en/moodle.php
  3. +62 −0 lib/locallib.php
View
3 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.
View
1 lang/en/moodle.php
@@ -248,6 +248,7 @@
$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';
View
62 lib/locallib.php
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * This file should be a series of functions that provide hooks for customisations
+ * to play happily. To have local database customisations, provide the following
+ *
+ * local/
+ * local/version.php
+ * local/db/{$CFG->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!');
+ }
+}
+
+
+?>

0 comments on commit 43e664c

Please sign in to comment.