From 7be1dff6aad094e7238c26d27ff64d71bb272884 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Wed, 6 Jan 2021 19:31:55 +0100 Subject: [PATCH] Option d'activation ou de suppression des fichiers back.json qui deviennent backup.json --- core/class/jsondb/JsonDb.class.php | 4 ++-- core/core.php | 20 +++++++++++++++---- core/module/config/config.php | 19 +++++++++++------- core/module/config/view/advanced/advanced.php | 6 ++++++ core/module/install/ressource/defaultdata.php | 1 + 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/core/class/jsondb/JsonDb.class.php b/core/class/jsondb/JsonDb.class.php index 2cb9d394..978a813a 100755 --- a/core/class/jsondb/JsonDb.class.php +++ b/core/class/jsondb/JsonDb.class.php @@ -132,8 +132,8 @@ class JsonDb extends \Prowebcraft\Dot touch($this->db); } // Backup file - if ($this->config['backup']) { - copy ($this->db, str_replace('json' , 'back.json', $this->db)); + if ($this->config['backup'] === true) { + copy ($this->db, str_replace('json' , 'backup.json', $this->db)); } if ( is_writable($this->db) ) { // 3 essais diff --git a/core/core.php b/core/core.php index 22f1d855..2e5bc281 100755 --- a/core/core.php +++ b/core/core.php @@ -44,7 +44,7 @@ class common { const ACCESS_TIMER = 1800; // Numéro de version - const ZWII_VERSION = '10.4.00.011'; + const ZWII_VERSION = '10.4.00.012'; const ZWII_UPDATE_CHANNEL = "v10"; public static $actions = []; @@ -168,10 +168,10 @@ class common { // Descripteur de données Entrées / Sorties // Liste ici tous les fichiers de données private $dataFiles = [ + 'config' => '', 'page' => '', 'module' => '', 'core' => '', - 'config' => '', 'page' => '', 'user' => '', 'theme' => '', @@ -198,13 +198,13 @@ class common { } // Instanciation de la classe des entrées / sorties - // Récupére les descripteurs + // Récupère les descripteurs foreach ($this->dataFiles as $keys => $value) { // Constructeur JsonDB $this->dataFiles[$keys] = new \Prowebcraft\JsonDb([ 'name' => $keys . '.json', 'dir' => $this->dataPath ($keys,self::$i18nCurrent), - 'backup' => true + 'backup' => $keys === 'config' ? true : $this->getData(['config','fileBackup']) ]);; } @@ -1565,6 +1565,18 @@ class common { $this->setData(['locale','metaDescription',$this->getData(['config','metaDescription'])]); $this->setData(['locale','title',$this->getData(['config','title'])]); + // Renommer les fichier de backup + if ($this->getInput('configAdvancedFileBackup', helper::FILTER_BOOLEAN) === false) { + $path = realpath('site/data'); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename) + { + echo "$filename
"; + if (strpos($filename,'back.json')) { + rename($filename, str_replace('back.json','backup.json',$filename)); + } + } + } + $this->setData(['core', 'dataVersion', 10400]); /** diff --git a/core/module/config/config.php b/core/module/config/config.php index 6b1c80b4..355e9393 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -485,6 +485,7 @@ class config extends common { [ 'analyticsId' => $this->getInput('configAdvancedAnalyticsId'), 'autoBackup' => $this->getInput('configAdvancedAutoBackup', helper::FILTER_BOOLEAN), + 'fileBackup' => $this->getInput('configAdvancedFileBackup', helper::FILTER_BOOLEAN), 'maintenance' => $this->getInput('configAdvancedMaintenance', helper::FILTER_BOOLEAN), 'cookieConsent' => $this->getInput('configAdvancedCookieConsent', helper::FILTER_BOOLEAN), 'favicon' => $this->getInput('configAdvancedFavicon'), @@ -525,7 +526,17 @@ class config extends common { ] ] ]); - + // Efface les fichiers de backup lorsque l'option est désactivée + if ($this->getInput('configAdvancedFileBackup', helper::FILTER_BOOLEAN) === false) { + $path = realpath('site/data'); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename) + { + if (strpos($filename,'backup.json')) { + unlink($filename); + } + } + } + // Notice if(self::$inputNotices === []) { // Active la réécriture d'URL $rewrite = $this->getInput('rewrite', helper::FILTER_BOOLEAN); @@ -572,12 +583,6 @@ class config extends common { 'state' => $success ]); } - // Initialisation du screen - APPEL AUTO DESACTIVE POUR EVITER UN RALENTISSEMENT - /* - if (!file_exists(self::FILE_DIR.'source/screenshot.jpg')) { - $this->configMetaImage(); - } - */ // Valeurs en sortie $this->addOutput([ 'title' => 'Configuration avancée', diff --git a/core/module/config/view/advanced/advanced.php b/core/module/config/view/advanced/advanced.php index c6843756..7bcd6a4a 100644 --- a/core/module/config/view/advanced/advanced.php +++ b/core/module/config/view/advanced/advanced.php @@ -101,6 +101,12 @@ 'help' => '

Une archive contenant le dossier /site/data est copiée dans le dossier \'site/backup\'. La sauvegarde est conservée pendant 30 jours.

Les fichiers du site ne sont pas sauvegardés automatiquement.

' ]); ?> +
+ $this->getData(['config', 'fileBackup']), + 'help' => '

Un fichier .backup.json est généré à chaque édition ou effacement d\'une donnée. La désactivation entraîne la suppression de ces fichiers.

' + ]); ?> +
diff --git a/core/module/install/ressource/defaultdata.php b/core/module/install/ressource/defaultdata.php index c6ef26dd..3527fa2a 100755 --- a/core/module/install/ressource/defaultdata.php +++ b/core/module/install/ressource/defaultdata.php @@ -4,6 +4,7 @@ class init extends common { 'config' => [ 'analyticsId' => '', 'autoBackup' => true, + 'fileBackup' => true, 'autoUpdate' => true, 'autoUpdateHtaccess' => false, 'cookieConsent' => true,