mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Now backup and restore are using central zip & unzip functions.
Merged from MOODLE_14_STABLE
This commit is contained in:
parent
0e919226b1
commit
17841181b6
2 changed files with 8 additions and 56 deletions
|
@ -1266,46 +1266,17 @@
|
||||||
$basedir = cleardoubleslashes($CFG->dataroot."/temp/backup/".$preferences->backup_unique_code);
|
$basedir = cleardoubleslashes($CFG->dataroot."/temp/backup/".$preferences->backup_unique_code);
|
||||||
//Backup zip file name
|
//Backup zip file name
|
||||||
$name = $preferences->backup_name;
|
$name = $preferences->backup_name;
|
||||||
//List base_dir files and directories
|
//List of files and directories
|
||||||
$filelist = list_directories_and_files ($basedir);
|
$filelist = list_directories_and_files ($basedir);
|
||||||
|
|
||||||
if (empty($CFG->zip)) { // Use built-in php-based zip function
|
//Convert them to full paths
|
||||||
//echo "<br />Using pclzip"; //Debug
|
|
||||||
$files = array();
|
|
||||||
foreach ($filelist as $file) {
|
foreach ($filelist as $file) {
|
||||||
//If directory, append "/"
|
$files[] = "$basedir/$file";
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//echo "<br />Status: ".$status; //Debug
|
$status = zip_files($files, "$basedir/$name");
|
||||||
|
|
||||||
|
//echo "<br>Status: ".$status; //Debug
|
||||||
return $status;
|
return $status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,8 @@
|
||||||
//It automatically uses pclzip or command line unzip
|
//It automatically uses pclzip or command line unzip
|
||||||
function restore_unzip ($file) {
|
function restore_unzip ($file) {
|
||||||
|
|
||||||
global $CFG;
|
return unzip_file($file, '', false);
|
||||||
|
|
||||||
$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 $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//This function checks if moodle.xml seems to be a valid xml file
|
//This function checks if moodle.xml seems to be a valid xml file
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue