Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved the check_version code to lib.php
Formatted portions of code
  • Loading branch information
stronk7 committed May 16, 2003
1 parent 740aa00 commit 7641819
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 76 deletions.
44 changes: 3 additions & 41 deletions backup/backup.php
Expand Up @@ -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");
Expand All @@ -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;
Expand Down
58 changes: 23 additions & 35 deletions backup/backuplib.php
Expand Up @@ -826,42 +826,30 @@ function backup_zip ($preferences,$moodle_home) {
$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;

Expand Down
48 changes: 48 additions & 0 deletions backup/lib.php
Expand Up @@ -254,4 +254,52 @@ function backup_copy_dir($from_file,$to_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;
}
}
}
?>

0 comments on commit 7641819

Please sign in to comment.