]> git.mjollnir.org Git - moodle.git/commitdiff
Further integration of backup into main Moodle.
authormoodler <moodler>
Fri, 1 Aug 2003 13:59:17 +0000 (13:59 +0000)
committermoodler <moodler>
Fri, 1 Aug 2003 13:59:17 +0000 (13:59 +0000)
The database checks/upgrades are now done on the main
admin page like the other modules.

The database files are now standard format .sql and .php files

PostgreSQL support was added - BUT HAS NOT BEEN TESTED YET!!

admin/index.php
backup/backup.php
backup/db/mysql.php [moved from backup/db/backup_mysql.php with 100% similarity]
backup/db/mysql.sql [new file with mode: 0644]
backup/db/postgres7.php [new file with mode: 0644]
backup/db/postgres7.sql [new file with mode: 0644]
backup/lib.php
backup/restore.php

index 837ecf29af814644cf4d6b9c63b761e1fab93987..71ef12c3162ca913484139d0c5e868287a55ef2b 100644 (file)
     }
 
 
+/// 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") ) {
index 46879f32d4fc0d4a8c63dd4e8625448eb64dbde9..eb516896175f0477cfd7c55fb3f90cfa05febcb7 100644 (file)
@@ -14,8 +14,6 @@
     //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");
 
@@ -39,7 +37,7 @@
     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");
diff --git a/backup/db/mysql.sql b/backup/db/mysql.sql
new file mode 100644 (file)
index 0000000..696f2ac
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# 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';
+
diff --git a/backup/db/postgres7.php b/backup/db/postgres7.php
new file mode 100644 (file)
index 0000000..3bd5f28
--- /dev/null
@@ -0,0 +1,34 @@
+<?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;
+
+}
+
+?>
diff --git a/backup/db/postgres7.sql b/backup/db/postgres7.sql
new file mode 100644 (file)
index 0000000..8a951ee
--- /dev/null
@@ -0,0 +1,34 @@
+# 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)
+
index 84611420eedffee753b5cf392aa7e193881dc843..d0491e3a5bda0f55889f5fcb9b3b9366c115e2cb 100644 (file)
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-    //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
index f739fa8f98a15e6ae8edd8fe1cd3209d53d3ccd0..9cc6b61bcc05c981ea8a9f37dc9e9e90d200c2fc 100644 (file)
@@ -3,21 +3,14 @@
 
     //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");
 
@@ -46,7 +39,8 @@
     } else {
         $linkto = "restore.php";
     }
-    upgrade_backup_db($backup_version,$backup_release,$linkto);
+
+    upgrade_backup_db($linkto);
 
     //Get strings
     $strcourserestore = get_string("courserestore");