}
+/// Upgrade backup/restore system if necessary
+
+ require_once("$CFG->dirroot/backup/lib.php");
+ upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
+
+
/// Find and check all modules and load them up or upgrade them if necessary
if (!$mods = get_list_of_plugins("mod") ) {
//Units used
require_once ("$moodle_home/config.php");
require_once ("$moodle_home/version.php");
- require_once ("version.php");
- require_once ("db/backup_$CFG->dbtype.php");
require_once ("lib.php");
require_once ("backuplib.php");
backup_required_functions();
//Check backup_version
- upgrade_backup_db($backup_version,$backup_release,"backup.php");
+ upgrade_backup_db("backup.php");
//Get strings
$strcoursebackup = get_string("coursebackup");
--- /dev/null
+#
+# Table structure for table `prefix_backup_files`
+#
+
+CREATE TABLE `prefix_backup_files` (
+ `backup_code` int(10) unsigned NOT NULL default '0',
+ `file_type` varchar(10) NOT NULL default '',
+ `path` varchar(255) NOT NULL default '',
+ `old_id` int(10) unsigned default NULL,
+ `new_id` int(10) unsigned default NULL,
+ PRIMARY KEY (`backup_code`,`file_type`,`path`)
+) TYPE=MyISAM COMMENT='To store and recode ids to user and course files.';
+# --------------------------------------------------------
+
+#
+# Table structure for table `prefix_backup_ids`
+#
+
+CREATE TABLE `prefix_backup_ids` (
+ `backup_code` int(12) unsigned NOT NULL default '0',
+ `table_name` varchar(30) NOT NULL default '',
+ `old_id` int(10) unsigned NOT NULL default '0',
+ `new_id` int(10) unsigned default NULL,
+ `info` mediumtext,
+ PRIMARY KEY (`backup_code`,`table_name`,`old_id`)
+) TYPE=MyISAM COMMENT='To store and convert ids in backup/restore';
+
--- /dev/null
+<?PHP //$Id$
+//
+// This file keeps track of upgrades to Moodle's
+// backup/restore utility.
+//
+// Sometimes, changes between versions involve
+// alterations to database structures and other
+// major things that may break installations.
+//
+// The upgrade function in this file will attempt
+// to perform all the necessary actions to upgrade
+// your older installtion to the current version.
+//
+// If there's something it cannot do itself, it
+// will tell you what you need to do.
+//
+// Versions are defined by backup_version.php
+//
+
+function backup_upgrade($oldversion=0) {
+
+ global $CFG;
+
+ $result = true;
+
+
+
+
+
+ return $result;
+
+}
+
+?>
--- /dev/null
+# THIS FILE IS UNTESTED!!!
+# PLEASE HELP TEST/FIX IT AND CONTACT MARTIN OR ELOY!
+
+#
+# Table structure for table prefix_backup_files
+#
+
+CREATE TABLE prefix_backup_files (
+ prefix_backup_codetypepath_idx PRIMARY KEY,
+ backup_code integer NOT NULL default '0',
+ file_type varchar(10) NOT NULL default '',
+ path varchar(255) NOT NULL default '',
+ old_id integer default NULL,
+ new_id integer default NULL,
+) TYPE=MyISAM COMMENT='To store and recode ids to user and course files.';
+# --------------------------------------------------------
+
+CREATE INDEX prefix_backup_codetypepath_idx ON prefix_backup_files (backup_code,file_type,path)
+
+#
+# Table structure for table prefix_backup_ids
+#
+
+CREATE TABLE prefix_backup_ids (
+ prefix_backup_codenameid_idx PRIMARY KEY,
+ backup_code int(12) unsigned NOT NULL default '0',
+ table_name varchar(30) NOT NULL default '',
+ old_id int(10) unsigned NOT NULL default '0',
+ new_id int(10) unsigned default NULL,
+ info mediumtext,
+) TYPE=MyISAM COMMENT='To store and convert ids in backup/restore';
+
+CREATE INDEX prefix_backup_codenameid_idx ON prefix_backup_ids (backup_code,table_name,old_id)
+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //This function upgrades, if necesary, the backup-restore tables
- //It's called from backup.php and restore.php
- function upgrade_backup_db($updgradeto,$backup_release,$continueto) {
+
+ function upgrade_backup_db($continueto) {
+ /// This function upgrades the backup tables, if necessary
+ /// It's called from admin/index.php, also backup.php and restore.php
- global $CFG,$db;
-
- //Check backup_version
- if ($CFG->backup_version) {
- if ($updgradeto > $CFG->backup_version) { // upgrade
- $a->oldversion = $CFG->backup_version;
- $a->newversion = $updgradeto;
- $strdatabasechecking = get_string("databasechecking", "", $a);
- $strdatabasesuccess = get_string("databasesuccess");
- print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking);
- print_heading($strdatabasechecking);
- $db->debug=true;
- if (backup_upgrade($a->oldversion)) {
- $db->debug=false;
- if (set_config("backup_version", $a->newversion)) {
- notify($strdatabasesuccess, "green");
- notify("You are running Backup/Recovery version ".$backup_release,"black");
- print_continue($continueto);
- die;
- } else {
- notify("Upgrade failed! (Could not update version in config table)");
- die;
- }
+ global $CFG, $db;
+
+ require_once ("$CFG->dirroot/backup/version.php"); // Get code versions
+
+ if (empty($CFG->backup_version)) { // Backup has never been installed.
+ $strdatabaseupgrades = get_string("databaseupgrades");
+ print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
+
+ $db->debug=true;
+ if (modify_database("$CFG->dirroot/backup/db/$CFG->dbtype.sql")) {
+ $db->debug = false;
+ if (set_config("backup_version", $backup_version)) {
+ notify(get_string("databasesuccess"), "green");
+ notify(get_string("databaseupgradebackups", "", $backup_release));
+ print_continue($continueto);
+ exit;
} else {
- $db->debug=false;
- notify("Upgrade failed! See version.php");
- die;
+ error("Upgrade of backup system failed! (Could not update version in config table)");
}
- } else if ($updgradeto < $CFG->backup_version) {
- notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
+ } else {
+ error("Backup tables could NOT be set up successfully!");
}
- //Not exists. Starting installation
- } else {
+ }
+
+
+ if ($backup_version > $CFG->backup_version) { // Upgrade tables
$strdatabaseupgrades = get_string("databaseupgrades");
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
-
- if (set_config("backup_version", "2003010100")) {
- print_heading("You are currently going to install the needed structures to Backup/Recover");
- print_continue($continueto);
- die;
+
+ require_once ("$CFG->dirroot/backup/db/$CFG->dbtype.php");
+
+ $db->debug=true;
+ if (backup_upgrade($CFG->backup_version)) {
+ $db->debug=false;
+ if (set_config("backup_version", $backup_version)) {
+ notify(get_string("databasesuccess"), "green");
+ notify(get_string("databaseupgradebackups", "", $backup_release));
+ print_continue($continueto);
+ exit;
+ } else {
+ error("Upgrade of backup system failed! (Could not update version in config table)");
+ }
+ } else {
+ $db->debug=false;
+ error("Upgrade failed! See backup/version.php");
}
+
+ } else if ($backup_version < $CFG->backup_version) {
+ notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
}
}
+
//This function is used to insert records in the backup_ids table
//If the info field is greater than max_db_storage, then its info
//Define some globals for all the script
- //MUST CHANGE WITH FINAL BACKUP LOCATION !! WITHOUT TRAILING SLASH !!
- //ALL RELATIVE FROM THE LOCATION OF THE restore.php SCRIPT !!!
-
$moodle_home = "..";
$mods_home = "../mod";
- //END MUST CHANGE
-
//Units used
require_once ("$moodle_home/config.php");
require_once ("$moodle_home/version.php");
require_once ("$moodle_home/lib/xmlize.php");
require_once ("$moodle_home/course/lib.php");
- require_once ("version.php");
- require_once ("db/backup_$CFG->dbtype.php");
require_once ("lib.php");
require_once ("restorelib.php");
} else {
$linkto = "restore.php";
}
- upgrade_backup_db($backup_version,$backup_release,$linkto);
+
+ upgrade_backup_db($linkto);
//Get strings
$strcourserestore = get_string("courserestore");