From b294bc4b1df5c34d03a08b744e2666e291a245c8 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 11 May 2003 11:06:23 +0000 Subject: [PATCH] Zipping files. Ok under command line. Bad under pcl lib --- backup/backup_execute.html | 7 +++++ backup/lib.php | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/backup/backup_execute.html b/backup/backup_execute.html index 13338152b1..d0305b17ab 100644 --- a/backup/backup_execute.html +++ b/backup/backup_execute.html @@ -226,6 +226,13 @@ } } + //Now, zip all the backup directory contents + if ($status) { + echo "
  • Zipping backup"; + $status = backup_zip ($preferences,$moodle_home); + + } + if (!$status) { error ("An error has ocurred"); } diff --git a/backup/lib.php b/backup/lib.php index 9bec3629c3..5ca57c0257 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -985,6 +985,61 @@ return $results; } + //This function creates the zip file containing all the backup info + //moodle.xml, moddata, user_files, course_files. + //The zipped file is created in the backup directory and named with + //the "oficial" name of the backup + //It uses "pclzip" if available or system "zip" (unix only) + function backup_zip ($preferences,$moodle_home) { + + global $CFG; + + $status = true; + + //Base dir where everything happens + $basedir = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code; + //Backup xip file name + $name = $preferences->backup_name; + //List base_dir files and directories + $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; + } + $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); + } + + return $status; + + } + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //This functions are used to copy any file or directory ($from_file) -- 2.39.5