Browse files

Now backup and restore are using central zip & unzip functions.

  • Loading branch information...
1 parent 20b53a7 commit 3eb92f112c6b865e50ab1f0eb877e75fa0a35a8c stronk7 committed Oct 16, 2004
Showing with 7 additions and 55 deletions.
  1. +6 −35 backup/backuplib.php
  2. +1 −20 backup/restorelib.php
View
41 backup/backuplib.php
@@ -1265,45 +1265,16 @@ function backup_zip ($preferences) {
$basedir = cleardoubleslashes($CFG->dataroot."/temp/backup/".$preferences->backup_unique_code);
//Backup zip file name
$name = $preferences->backup_name;
- //List base_dir files and directories
+ //List of files and directories
$filelist = list_directories_and_files ($basedir);
- if (empty($CFG->zip)) { // Use built-in php-based zip function
- //echo "<br>Using pclzip"; //Debug
- $files = array();
- foreach ($filelist as $file) {
- //If directory, append "/"
- //Commented. Not needed wit version 2.0 of pclzip !!
- //if (is_dir($basedir."/".$file)) {
- // $file = $file."/";
- //}
- //Include into array
- //echo "<br>Adding file/dir ".$file; //Debug
- $files[] = cleardoubleslashes($basedir."/".$file);
- }
- include_once("$CFG->dirroot/lib/pclzip/pclzip.lib.php");
- //include_once("$CFG->dirroot/lib/pclzip/pclerror.lib.php"); //Debug
- //include_once("$CFG->dirroot/lib/pclzip/pcltrace.lib.php"); //Debug
- //PclTraceOn(2); //Debug
- $archive = new PclZip(cleardoubleslashes("$basedir/$name"));
- if (($list = $archive->create($files,PCLZIP_OPT_REMOVE_PATH,rtrim(cleardoubleslashes($basedir), "/"))) == 0) {
- error($archive->errorInfo(true));
- $status = false;
- }
- //PclTraceDisplay(); //Debug
- //PclTraceOff(); //Debug
- } else { // Use external zip program
- //echo "<br>Using external zip"; //Debug
- $files = "";
- foreach ($filelist as $file) {
- $files .= basename($file);
- $files .= " ";
- }
- $command = "cd $basedir ; $CFG->zip -r $name $files";
- //echo "<br>Executing command: ".$command; //Debug
- $status = Exec($command);
+ //Convert them to full paths
+ foreach ($filelist as $file) {
+ $files[] = "$basedir/$file";
}
+ $status = zip_files($files, "$basedir/$name");
+
//echo "<br>Status: ".$status; //Debug
return $status;
View
21 backup/restorelib.php
@@ -5,27 +5,8 @@
//It automatically uses pclzip or command line unzip
function restore_unzip ($file) {
- global $CFG;
-
- $status = true;
-
- if (empty($CFG->unzip)) { // Use built-in php-based unzip function
- include_once("$CFG->dirroot/lib/pclzip/pclzip.lib.php");
- //include_once("$CFG->dirroot/lib/pclzip/pclerror.lib.php"); //Debug
- //include_once("$CFG->dirroot/lib/pclzip/pcltrace.lib.php"); //Debug
- //PclTraceOn(2); //Debug
- $archive = new PclZip(cleardoubleslashes($file));
- if (!$list = $archive->extract(PCLZIP_OPT_PATH, cleardoubleslashes(dirname($file)))) {
- $status = false;
- }
- //PclTraceDisplay(); //Debug
- //PclTraceOff(); //Debug
- } else { // Use external unzip program
- $command = "cd ".dirname($file)."; $CFG->unzip -o ".basename($file);
- Exec($command);
- }
+ return unzip_file($file, '', false);
- return $status;
}
//This function checks if moodle.xml seems to be a valid xml file

0 comments on commit 3eb92f1

Please sign in to comment.