From 17841181b6c83b9d1aa2bc6a9ca94174342e3bc8 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 16 Oct 2004 17:34:56 +0000 Subject: [PATCH] Now backup and restore are using central zip & unzip functions. Merged from MOODLE_14_STABLE --- backup/backuplib.php | 43 +++++++------------------------------------ backup/restorelib.php | 21 +-------------------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/backup/backuplib.php b/backup/backuplib.php index 6b580966cf..66fe9f5d82 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1266,46 +1266,17 @@ $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 "
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 "
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 "
Using external zip"; //Debug - $files = ""; - foreach ($filelist as $file) { - $files .= basename($file); - $files .= " "; - } - $command = "cd $basedir ; $CFG->zip -r $name $files"; - //echo "
Executing command: ".$command; //Debug - $status = Exec($command); + //Convert them to full paths + foreach ($filelist as $file) { + $files[] = "$basedir/$file"; } - //echo "
Status: ".$status; //Debug + $status = zip_files($files, "$basedir/$name"); + + //echo "
Status: ".$status; //Debug return $status; } diff --git a/backup/restorelib.php b/backup/restorelib.php index e118b86c41..8a62bdfb01 100644 --- a/backup/restorelib.php +++ b/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 -- 2.39.5