From: stronk7 Date: Fri, 16 May 2003 21:51:07 +0000 (+0000) Subject: Moved the check_version code to lib.php X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7641819df08df89a39f718688e43be01d9fadfda;p=moodle.git Moved the check_version code to lib.php Formatted portions of code --- diff --git a/backup/backup.php b/backup/backup.php index 9f31bb6a47..e310ab0bc4 100644 --- a/backup/backup.php +++ b/backup/backup.php @@ -32,49 +32,11 @@ //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; diff --git a/backup/backuplib.php b/backup/backuplib.php index a75ca081fa..465e6b095a 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -826,42 +826,30 @@ $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 "
"; - $list = $archive->listContent(); - for ($i=0; $i"; - } - echo "
"; - } - } - } 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; diff --git a/backup/lib.php b/backup/lib.php index 0cdc7c1a2d..75a1900ce6 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -254,4 +254,52 @@ ///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; + } + } + } ?>