]> git.mjollnir.org Git - moodle.git/commitdiff
Moved the check_version code to lib.php
authorstronk7 <stronk7>
Fri, 16 May 2003 21:51:07 +0000 (21:51 +0000)
committerstronk7 <stronk7>
Fri, 16 May 2003 21:51:07 +0000 (21:51 +0000)
Formatted portions of code

backup/backup.php
backup/backuplib.php
backup/lib.php

index 9f31bb6a47d0b246714c8d81f956c86192e9affd..e310ab0bc4e0b28714463161dae9024721b15891 100644 (file)
 
     //Check site
     if (!$site = get_site()) {
-        error("Site noto found!");
+        error("Site not found!");
     }
     
     //Check backup_version
-    if ($CFG->backup_version) {
-        if ($backup_version > $CFG->backup_version) {  // upgrade
-            $a->oldversion = $CFG->backup_version;
-            $a->newversion = $backup_version;
-            $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("backup.php");
-                    die;
-                } else {
-                    notify("Upgrade failed!  (Could not update version in config table)");
-                    die;
-                }
-            } else {
-                $db->debug=false;
-                notify("Upgrade failed!  See backup_version.php");
-                die;
-            }
-        } else if ($backup_version < $CFG->backup_version) {
-            notify("WARNING!!!  The code you are using is OLDER than the version that made these databases!");
-        }
-    //Not exists. Starting installation
-    } else {
-        $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("backup.php");
-            die;
-        }
-    }
+    upgrade_backup_db($backup_version,$backup_release,"backup.php");
 
     //Get strings
     $strcoursebackup = get_string("coursebackup");
@@ -94,7 +56,7 @@
             print_simple_box_end();
         } else {
             print_heading(get_string("nocoursesyet"));
-            print_continue("../$CFG->admin/index.php");
+            print_continue("$moodle_home/$CFG->admin/index.php");
         }
         print_footer();
         exit;
index a75ca081fab7641d7ef86f47a2d93f0e6d39417f..465e6b095a6a06dfc108e2354f5c184077ab1789 100644 (file)
         $filelist = list_directories_and_files ($basedir);
 
         if (empty($CFG->zip)) {    // Use built-in php-based zip function
-                    $files = array();
-                    foreach ($filelist as $file) {
-                        //If directory, append "/"
-                        if (is_dir($basedir."/".$file)) {
-                            $file = $file."/";
-                        }
-                        //Include into array
-                        $files[] = $basedir."/".$file;
-                    }
-                    include_once($moodle_home."/lib/pclzip/pclzip.lib.php");
-                    $archive = new PclZip("$basedir/$name");
-                    if (($list = $archive->create($files,PCLZIP_OPT_REMOVE_PATH,$basedir)) == 0) {
-                        error($archive->errorInfo(true));
-                        $status = false;
-                    } 
-                    //Debug zip contents
-                    //true->do it, false->don't do it. To debug if necessary.
-                    if (false) {
-                        echo "<br>";
-                        $list = $archive->listContent();
-                        for ($i=0; $i<sizeof($list); $i++) {
-                            for(reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
-                                echo "File $i / [$key] = ".$list[$i][$key]."<br>";
-                            }
-                        echo "<br>";
-                        }
-                    }
-                } else {                   // Use external zip program
-                    $files = "";
-                    foreach ($filelist as $file) {
-                        $files .= basename($file);
-                        $files .= " ";
-                    }
-                    $command = "cd $basedir ; $CFG->zip -r $name $files";
-                    $status = Exec($command);
+            $files = array();
+            foreach ($filelist as $file) {
+                //If directory, append "/"
+                if (is_dir($basedir."/".$file)) {
+                    $file = $file."/";
                 }
+                //Include into array
+                $files[] = $basedir."/".$file;
+            }
+            include_once($moodle_home."/lib/pclzip/pclzip.lib.php");
+            $archive = new PclZip("$basedir/$name");
+            if (($list = $archive->create($files,PCLZIP_OPT_REMOVE_PATH,$basedir)) == 0) {
+                error($archive->errorInfo(true));
+                $status = false;
+            } 
+        } else {                   // Use external zip program
+            $files = "";
+            foreach ($filelist as $file) {
+                $files .= basename($file);
+                $files .= " ";
+            }
+            $command = "cd $basedir ; $CFG->zip -r $name $files";
+            $status = Exec($command);
+        }
 
         return $status;
 
index 0cdc7c1a2deaa274c3d8ea3754b21a867d4a74ac..75a1900ce616a74fc33d1366278c115326864915 100644 (file)
     ///Ends copy file/dirs functions
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+    //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) {
+    
+        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;
+                    }
+                } else {
+                    $db->debug=false;
+                    notify("Upgrade failed!  See backup_version.php");
+                    die;
+                }
+            } else if ($updgradeto < $CFG->backup_version) {
+                notify("WARNING!!!  The code you are using is OLDER than the version that made these databases!");
+            }
+        //Not exists. Starting installation
+        } else {
+            $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($continue_to);
+                die;
+            }
+        }
+    }
 ?>