[10.0.028.dev] Backup revu et corrigé, reste option dossier data inclus ou pas
This commit is contained in:
parent
ca1e2ba5cb
commit
d42cc357fd
@ -42,6 +42,43 @@ class helper {
|
||||
return $newArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Génére un backup des données de site
|
||||
* @param string $folder dossier de sauvegarde
|
||||
* @param array $exclude dossier exclus
|
||||
* @return string nom du fichier de sauvegarde
|
||||
*/
|
||||
|
||||
public static function autoBackup($folder, $filter = ['backup','tmp'] ) {
|
||||
// Creation du ZIP
|
||||
$fileName = str_replace('/','',helper::baseUrl(false,false)) . '-'. date('Y-m-d-h-i-s', time()) . '.zip';
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($folder . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
$directory = 'site/';
|
||||
//$filter = array('backup','tmp','file');
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveCallbackFilterIterator(
|
||||
new RecursiveDirectoryIterator(
|
||||
$directory,
|
||||
RecursiveDirectoryIterator::SKIP_DOTS
|
||||
),
|
||||
function ($fileInfo, $key, $iterator) use ($filter) {
|
||||
return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
|
||||
}
|
||||
)
|
||||
);
|
||||
foreach ($files as $name => $file) {
|
||||
if (!$file->isDir()) {
|
||||
$filePath = $file->getRealPath();
|
||||
$relativePath = substr($filePath, strlen(realpath($directory)) + 1);
|
||||
$zip->addFile($filePath, $relativePath);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
return ($fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne l'URL de base du site
|
||||
* @param bool $queryString Affiche ou non le point d'interrogation
|
||||
|
@ -34,7 +34,7 @@ class common {
|
||||
const TEMP_DIR = 'site/tmp/';
|
||||
|
||||
// Numéro de version
|
||||
const ZWII_VERSION = '10.0.027.dev';
|
||||
const ZWII_VERSION = '10.0.028.dev';
|
||||
|
||||
public static $actions = [];
|
||||
public static $coreModuleIds = [
|
||||
@ -888,6 +888,7 @@ class common {
|
||||
$db->save;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mises à jour
|
||||
*/
|
||||
@ -1103,8 +1104,9 @@ class core extends common {
|
||||
AND $lastBackup > $this->getData(['core', 'lastBackup']) + 86400
|
||||
AND $this->getData(['user']) // Pas de backup pendant l'installation
|
||||
) {
|
||||
// Copie du fichier de données
|
||||
copy(self::DATA_DIR.'core.json', self::BACKUP_DIR . date('Y-m-d', $lastBackup) . '.json');
|
||||
// Copie des fichier de données
|
||||
//copy(self::DATA_DIR.'core.json', self::BACKUP_DIR . date('Y-m-d', $lastBackup) . '.json');
|
||||
helper::autoBackup(self::BACKUP_DIR,['backup','tmp','file']);
|
||||
// Date du dernier backup
|
||||
$this->setData(['core', 'lastBackup', $lastBackup]);
|
||||
// Enregistre les données
|
||||
|
@ -201,30 +201,9 @@ class config extends common {
|
||||
*/
|
||||
public function backup() {
|
||||
// Creation du ZIP
|
||||
$fileName = str_replace('/','',helper::baseUrl(false,false)) . '-'. date('Y-m-d-h-i-s', time()) . '.zip';
|
||||
$zip = new ZipArchive();
|
||||
$zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
$directory = 'site/';
|
||||
$filter = array('backup','tmp');
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveCallbackFilterIterator(
|
||||
new RecursiveDirectoryIterator(
|
||||
$directory,
|
||||
RecursiveDirectoryIterator::SKIP_DOTS
|
||||
),
|
||||
function ($fileInfo, $key, $iterator) use ($filter) {
|
||||
return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
|
||||
}
|
||||
)
|
||||
);
|
||||
foreach ($files as $name => $file) {
|
||||
if (!$file->isDir()) {
|
||||
$filePath = $file->getRealPath();
|
||||
$relativePath = substr($filePath, strlen(realpath($directory)) + 1);
|
||||
$zip->addFile($filePath, $relativePath);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
$filter = $this->getInput('configBackupOption',helper::FILTER_BOOLEAN) === true ? ['backup','tmp'] : ['backup','tmp','file'];
|
||||
$fileName = helper::autoBackup(self::TEMP_DIR,$filter);
|
||||
|
||||
// Téléchargement du ZIP
|
||||
header('Content-Type: application/zip');
|
||||
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
||||
@ -235,6 +214,7 @@ class config extends common {
|
||||
'display' => self::DISPLAY_RAW
|
||||
]);
|
||||
unlink(self::TEMP_DIR . $fileName);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,9 +15,18 @@
|
||||
<h4>Sauvegarde totale du site</h4>
|
||||
<div class="row">
|
||||
<div class="col10 offset1">
|
||||
<?php echo template::button('configManageButton', [
|
||||
<?php echo template::button('configBackupButton', [
|
||||
'href' => helper::baseUrl() . 'config/backup',
|
||||
'value' => 'Générer et télécharger <br />une archive des données de site',
|
||||
'value' => 'Générer et télécharger <br />les données de site',
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col10">
|
||||
<?php echo template::checkbox('configBackupOption', true, 'Inclure le contenu du gestionnaire de fichier', [
|
||||
'checked' => true,
|
||||
'disabled' => true,
|
||||
'help' => 'Cette option n\'est pas recommandée lorsque le contenu du gestionnaire de fichier est très volumineux.'
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user