[10.0.014.dev] backup nouvelle fonction

This commit is contained in:
Fred Tempez 2019-12-16 13:16:13 +01:00
parent 5419b3fa51
commit 6144253853
2 changed files with 36 additions and 5 deletions

View File

@ -34,7 +34,7 @@ class common {
const TEMP_DIR = 'site/tmp/'; const TEMP_DIR = 'site/tmp/';
// Numéro de version // Numéro de version
const ZWII_VERSION = '10.0.013.dev'; const ZWII_VERSION = '10.0.014.dev';
public static $actions = []; public static $actions = [];
public static $coreModuleIds = [ public static $coreModuleIds = [

View File

@ -204,16 +204,25 @@ class config extends common {
// Creation du ZIP // Creation du ZIP
$fileName = str_replace('/','',helper::baseUrl(false,false)) . '-'. date('Y-m-d-h-i-s', time()) . '.zip'; $fileName = str_replace('/','',helper::baseUrl(false,false)) . '-'. date('Y-m-d-h-i-s', time()) . '.zip';
$zip = new ZipArchive(); $zip = new ZipArchive();
if($zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE) === TRUE){
foreach(core::scanDir(self::DATA_DIR) as $file) { $zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFile($file);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(realpath(self::DATA_DIR)),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen(realpath(self::DATA_DIR)) + 1);
$zip->addFile($filePath, $relativePath);
} }
} }
$zip->close(); $zip->close();
// Enregistre la date de backup manuel // Enregistre la date de backup manuel
$this->setData(['core', 'lastBackup', mktime(0, 0, 0)]); $this->setData(['core', 'lastBackup', mktime(0, 0, 0)]);
// Téléchargement du ZIP // Téléchargement du ZIP
header('Content-Transfer-Encoding: binary'); header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName)); header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName));
readfile(self::TEMP_DIR . $fileName); readfile(self::TEMP_DIR . $fileName);
@ -478,4 +487,26 @@ class config extends common {
'view' => 'manage' 'view' => 'manage'
]); ]);
} }
public function recursiveDirectoryIterator ($directory = null, $files = array()) {
$iterator = new \DirectoryIterator ( $directory );
foreach ( $iterator as $info ) {
if ($info->isFile ()) {
$files [$info->__toString ()] = $info;
} elseif (!$info->isDot ()) {
$list = array($info->__toString () => $this->recursiveDirectoryIterator(
$directory.DIRECTORY_SEPARATOR.$info->__toString ()
));
if(!empty($files))
$files = array_merge_recursive($files, $filest);
else {
$files = $list;
}
}
}
return $files;
}
} }