]> git.mjollnir.org Git - moodle.git/commitdiff
Zipping files.
authorstronk7 <stronk7>
Sun, 11 May 2003 11:06:23 +0000 (11:06 +0000)
committerstronk7 <stronk7>
Sun, 11 May 2003 11:06:23 +0000 (11:06 +0000)
Ok under command line. Bad under pcl lib

backup/backup_execute.html
backup/lib.php

index 13338152b1ce3902f67c63fc1a0d713242bd5801..d0305b17ab728c4e86d20bd52f7b0da160325334 100644 (file)
         }
     }
 
+    //Now, zip all the backup directory contents
+    if ($status) {
+        echo "<li>Zipping backup";
+        $status = backup_zip ($preferences,$moodle_home);
+
+    }
+
     if (!$status) {
         error ("An error has ocurred");
     }
index 9bec3629c30f182c91510255d139dfafdfe8d7fd..5ca57c02572c33899be53ad34d2a1f774ce90415 100644 (file)
         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<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);
+                }
+
+        return $status;
+
+    } 
+
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     //This functions are used to copy any file or directory ($from_file)