From 63a831af1f77ac14f5fc3f18098178330f4c1dbb Mon Sep 17 00:00:00 2001 From: fredtempez Date: Tue, 14 Sep 2021 20:54:31 +0200 Subject: [PATCH] =?UTF-8?q?bug=20setPage=20+=20r=C3=A9=C3=A9criture=20de?= =?UTF-8?q?=20l'importation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core.php | 2 +- core/include/update.inc.php | 8 +++--- core/module/config/config.php | 48 +++++++++++++++++++++-------------- core/module/page/page.php | 4 +-- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/core/core.php b/core/core.php index 834078f3..91987943 100755 --- a/core/core.php +++ b/core/core.php @@ -485,7 +485,7 @@ class common { */ public function setPage($page, $value, $lang) { - return file_put_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']), $value); + return file_put_contents(self::DATA_DIR . $lang . '/content/' . $page . '.html', $value); } diff --git a/core/include/update.inc.php b/core/include/update.inc.php index 3a61f094..2acd1077 100644 --- a/core/include/update.inc.php +++ b/core/include/update.inc.php @@ -633,8 +633,8 @@ if ($this->getData(['core', 'dataVersion']) < 11000) { } foreach ($pageList as $parentKey => $parent) { $content = $this->getData(['page', $parent, 'content']); - // file_put_contents(self::DATA_DIR . self::$i18n . '/content/' . $parent . '.html', $content); - $this->setPage($parent, $content, self::$i18n); + //file_put_contents(self::DATA_DIR . self::$i18n . '/content/' . $parent . '.html', $content); + $this->setPage($parent, $content, 'fr'); $this->setData(['page', $parent, 'content', $parent . '.html']); } @@ -642,6 +642,4 @@ if ($this->getData(['core', 'dataVersion']) < 11000) { $this->setData(['config','seo','robots',true]); $this->setData(['core', 'dataVersion', 11000]); -} - -?> +} \ No newline at end of file diff --git a/core/module/config/config.php b/core/module/config/config.php index 75855924..2ab23b7e 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -193,7 +193,7 @@ class config extends common { $this->addOutput([ 'notification' => $successSitemap ? 'Mises à jour des fichiers sitemap et robots.txt' : 'Echec d\'écriture, le site map n\'a pas été mis à jour', 'redirect' => helper::baseUrl() . 'config/advanced', - 'state' => $successSitemap + 'state' => $successSitemap ]); } @@ -298,25 +298,35 @@ class config extends common { $files [] = ( basename( $stat['name'] )); } - // Détermination de la version à installer - if (in_array('theme.json',$files) === true && - in_array('core.json',$files) === true && - in_array ('user.json', $files) === false ) { - // V9 pas de fichier user dans l'archive - // Stocker le choix de conserver les users installées - $version = '9'; + // Lire la dataversion + $tmpDir = uniqid(4); + $success = $zip->extractTo( self::TEMP_DIR . $tmpDir ); + $data = file_get_contents( self::TEMP_DIR . $tmpDir . '/data/core.json'); + $obj = json_decode($data); + $dataVersion = strval ($obj->core->dataVersion); + switch (strlen($dataVersion)) { + case 4: + if (substr($dataVersion,0,1) === '9' ) { + $version = 9; + } else { + $version = 0; + } + break; + case 5: + $version = substr($dataVersion,0,2); + break; + default: + $version = 0; + break; + } + $this->removeDir(self::TEMP_DIR . $tmpDir ); - } elseif (in_array('theme.json',$files) === true && - in_array('core.json',$files) === true && - in_array ('user.json', $files) === true && - in_array ('config.json', $files) === true ) { - // V10 valide - $version = '10'; + if ($version >= 10 ) { // Option active, les users sont stockées if ($this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ) { $users = $this->getData(['user']); - } - } else { // Version invalide + } + } elseif ($version === 0) { // Version invalide // Valeurs en sortie erreur $this->addOutput([ 'notification' => 'Cette archive n\'est pas une sauvegarde valide', @@ -326,7 +336,7 @@ class config extends common { } // Préserver les comptes des utilisateurs d'une version 9 si option cochée // Positionnement d'une variable de session lue au constructeurs - if ($version === '9') { + if ($version === 9) { $_SESSION['KEEP_USERS'] = $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN); } // Extraire le zip ou 'site/' @@ -334,13 +344,13 @@ class config extends common { // Fermer l'archive $zip->close(); + // Restaurer les users originaux d'une v10 si option cochée if (!empty($users) && - $version === '10' && + $version >= 10 && $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true) { $this->setData(['user',$users]); } - // Message de notification $notification = $success === true ? 'Restauration réalisée avec succès' : 'Erreur inconnue'; $redirect = $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ? helper::baseUrl() . 'config/restore' : helper::baseUrl() . 'user/login/'; diff --git a/core/module/page/page.php b/core/module/page/page.php index a011d9ef..827fe57c 100644 --- a/core/module/page/page.php +++ b/core/module/page/page.php @@ -440,8 +440,8 @@ class page extends common { mkdir(self::DATA_DIR . self::$i18n . '/content'); } $content = empty($this->getInput('pageEditContent', null)) ? '

' : str_replace('

', '

 

', $this->getInput('pageEditContent', null)); - // file_put_contents( self::DATA_DIR . self::$i18n . '/content/' . $pageId . '.html' , $content ); - $this->setPage($pageId, $content, self::$i18n); + //file_put_contents( self::DATA_DIR . self::$i18n . '/content/' . $pageId . '.html' , $content ); + $this->setPage($pageId , $content, self::$i18n); // Barre renommée : changement le nom de la barre dans les pages mères if ($this->getinput('pageEditBlock') === 'bar') { foreach ($this->getHierarchy() as $eachPageId=>$parentId) {