From 614425385381638fcfae1bb2b8e510e5119a4a18 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Mon, 16 Dec 2019 13:16:13 +0100 Subject: [PATCH] [10.0.014.dev] backup nouvelle fonction --- core/core.php | 2 +- core/module/config/config.php | 39 +++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/core/core.php b/core/core.php index 6d05d535..96871f99 100644 --- a/core/core.php +++ b/core/core.php @@ -34,7 +34,7 @@ class common { const TEMP_DIR = 'site/tmp/'; // Numéro de version - const ZWII_VERSION = '10.0.013.dev'; + const ZWII_VERSION = '10.0.014.dev'; public static $actions = []; public static $coreModuleIds = [ diff --git a/core/module/config/config.php b/core/module/config/config.php index 8bd986aa..1f512315 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -204,16 +204,25 @@ class config extends common { // Creation du ZIP $fileName = str_replace('/','',helper::baseUrl(false,false)) . '-'. date('Y-m-d-h-i-s', time()) . '.zip'; $zip = new ZipArchive(); - if($zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE) === TRUE){ - foreach(core::scanDir(self::DATA_DIR) as $file) { - $zip->addFile($file); + + $zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE); + + $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(); // Enregistre la date de backup manuel $this->setData(['core', 'lastBackup', mktime(0, 0, 0)]); // Téléchargement du ZIP - header('Content-Transfer-Encoding: binary'); + header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName)); readfile(self::TEMP_DIR . $fileName); @@ -478,4 +487,26 @@ class config extends common { '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; + } + }