From 760257e3b28b76c020d7688c93211c8eeec2c8d1 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Tue, 1 Feb 2022 16:56:02 +0100 Subject: [PATCH] importData WIP --- core/module/plugin/plugin.php | 211 ++++++++++++------------ core/module/plugin/view/index/index.php | 28 ++-- core/module/plugin/view/store/store.php | 7 + truc | 1 - 4 files changed, 129 insertions(+), 118 deletions(-) delete mode 100644 truc diff --git a/core/module/plugin/plugin.php b/core/module/plugin/plugin.php index f7841e1c..21b70c20 100644 --- a/core/module/plugin/plugin.php +++ b/core/module/plugin/plugin.php @@ -475,12 +475,14 @@ class plugin extends common { 'href' => helper::baseUrl(). $this->getUrl(0) . '/dataExport/' . $keyi18n . '/' . $pagesInfos[$keyi18n][$keyPage]['moduleId'] . '/' . $keyPage . '/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre 'value' => template::ico('download'), 'help' => 'Exporter les données du module' - ]), + ]) + /* template::button('moduleImport' . $keyPage, [ 'href' => helper::baseUrl(). $this->getUrl(0) . '/dataImport/' . $keyi18n . '/' . $pagesInfos[$keyi18n][$keyPage]['moduleId'] . '/' . $keyPage . '/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre 'value' => template::ico('upload'), 'help' => 'Importer les données du module' ]) + */ ]; } } @@ -524,9 +526,7 @@ class plugin extends common { mkdir(self::FILE_DIR . 'source/modules'); } $success = copy($tmpFolder . '/' . $fileName , self::FILE_DIR . 'source/modules/' . $this->getUrl(3) . '.zip' ); - // Nettoyage - unlink($tmpFolder . '/' . $fileName); - $this->removeDir($tmpFolder); + // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . 'plugin', @@ -542,12 +542,12 @@ class plugin extends common { ob_clean(); ob_end_flush(); readfile( $tmpFolder . '/' .$fileName); - unlink($tmpFolder . '/' . $fileName); - $this->removeDir($tmpFolder); exit(); break; } - + // Nettoyage + unlink($tmpFolder . '/' . $fileName); + $this->removeDir($tmpFolder); } } @@ -570,24 +570,26 @@ class plugin extends common { if (!is_dir($tmpFolder)) { mkdir($tmpFolder, 0755); } - - // Sauvegarder la langue active - $saveI18n = self::$i18n; - - self::$i18n = $this->getUrl(2); + // Copie des infos sur le module - $moduleData = $this->getData(['module', $this->getUrl(4) ]); + $modulesData = json_decode(file_get_contents(self::DATA_DIR . $this->getUrl(2) . '/module.json' ), true); + $moduleData [$this->getUrl(4)] = $modulesData['module'] [$this->getUrl(4)]; $success = file_put_contents ($tmpFolder . '/module.json', json_encode($moduleData)); // Le dossier du module s'il existe if (is_dir(self::DATA_DIR . $this->getUrl(3) . '/' . $this->getUrl(4) ) ) { // Copier le dossier des données - $success = $this->copyDir(self::DATA_DIR . $this->getUrl(3) . '/' . $this->getUrl(4), $tmpFolder . '/' . self::DATA_DIR . $this->getUrl(3) . '/' . $this->getUrl(4)); - } + $success .= $this->copyDir(self::DATA_DIR . $this->getUrl(3) . '/' . $this->getUrl(4), $tmpFolder); + } + + // Descripteur de l'archive + $success .= file_put_contents ($tmpFolder . '/descripteur.json', json_encode([ + 'langue' => $this->getUrl(2), + 'page' => $this->getUrl(3), + 'module' => $this->getUrl(4) + ])); - // Restaurer la langue active - //self::$i18n = $saveI18n; // création du zip if ($success) @@ -621,110 +623,109 @@ class plugin extends common { * Importer des données d'un module externes ou interne à module.json */ public function dataImport(){ - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'plugin', - 'state' => false, - 'notification' => 'Action non autorisée' - ]); - } - else { - // Soumission du formulaire - if($this->isPost()) { - // Récupérer le fichier et le décompacter - $zipFilename = $this->getInput('pluginImportFile', helper::FILTER_STRING_SHORT, true); - $targetPage = $this->getInput('pluginImportPage', helper::FILTER_STRING_SHORT, true); - $tempFolder = uniqid(); - mkdir (self::TEMP_DIR . $tempFolder, 0755); - $zip = new ZipArchive(); - if ($zip->open(self::FILE_DIR . 'source/' . $zipFilename) === TRUE) { - $zip->extractTo(self::TEMP_DIR . $tempFolder ); - } - // copie du contenu de la page - $this->copyDir (self::TEMP_DIR . $tempFolder . '/' .$key . '/content', self::DATA_DIR . '/' .$key . '/content'); - // Supprimer les fichiers importés - unlink (self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json'); - // Import des fichiers placés ailleurs que dans les dossiers localisés. - $this->copyDir (self::TEMP_DIR . $tempFolder, self::DATA_DIR ); - + // Soumission du formulaire + if($this->isPost()) { + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'plugin', + 'state' => false, + 'notification' => 'Action non autorisée' + ]); + } + // Récupérer le fichier et le décompacter + $zipFilename = $this->getInput('pluginImportFile', helper::FILTER_STRING_SHORT, true); + $targetPage = $this->getInput('pluginImportPage', helper::FILTER_STRING_SHORT, true); + $tempFolder = uniqid(); + mkdir (self::TEMP_DIR . $tempFolder, 0755); + $zip = new ZipArchive(); + if ($zip->open(self::FILE_DIR . 'source/' . $zipFilename) === TRUE) { + $zip->extractTo(self::TEMP_DIR . $tempFolder ); + } - // Import des données localisées page.json et module.json - // Pour chaque dossier localisé - // $dataTarget = array(); - // $dataSource = array(); - + // copie du contenu de la page + $this->copyDir (self::TEMP_DIR . $tempFolder . '/' .$key . '/content', self::DATA_DIR . '/' .$key . '/content'); + // Supprimer les fichiers importés + unlink (self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json'); + // Import des fichiers placés ailleurs que dans les dossiers localisés. + $this->copyDir (self::TEMP_DIR . $tempFolder, self::DATA_DIR ); + - - // Liste des pages de même nom dans l'archive et le site - /* - $list = ''; - foreach (self::$i18nList as $key=>$value) { - // Les Pages et les modules - foreach (['page','module'] as $fileTarget){ - if (file_exists(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json')) { - // Le dossier de langue existe - // faire la fusion - $dataSource = json_decode(file_get_contents(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json'), true); - // Des pages de même nom que celles de l'archive existent - if( $fileTarget === 'page' ){ - foreach( $dataSource as $keydataSource=>$valuedataSource ){ - foreach( $this->getData(['page']) as $keypage=>$valuepage ){ - if( $keydataSource === $keypage){ - $list === '' ? $list .= ' '.$this->getData(['page', $keypage, 'title']) : $list .= ', '.$this->getData(['page', $keypage, 'title']); - } + // Import des données localisées page.json et module.json + // Pour chaque dossier localisé + // $dataTarget = array(); + // $dataSource = array(); + + + + // Liste des pages de même nom dans l'archive et le site + /* + $list = ''; + foreach (self::$i18nList as $key=>$value) { + // Les Pages et les modules + foreach (['page','module'] as $fileTarget){ + if (file_exists(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json')) { + // Le dossier de langue existe + // faire la fusion + $dataSource = json_decode(file_get_contents(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json'), true); + // Des pages de même nom que celles de l'archive existent + if( $fileTarget === 'page' ){ + foreach( $dataSource as $keydataSource=>$valuedataSource ){ + foreach( $this->getData(['page']) as $keypage=>$valuepage ){ + if( $keydataSource === $keypage){ + $list === '' ? $list .= ' '.$this->getData(['page', $keypage, 'title']) : $list .= ', '.$this->getData(['page', $keypage, 'title']); } } } - $dataTarget = json_decode(file_get_contents(self::DATA_DIR . $key . '/' . $fileTarget . '.json'), true); - $data [$fileTarget] = array_merge($dataTarget[$fileTarget], $dataSource); - if( $list === ''){ - file_put_contents(self::DATA_DIR . '/' .$key . '/' . $fileTarget . '.json', json_encode( $data ,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|LOCK_EX) ); - } + } + $dataTarget = json_decode(file_get_contents(self::DATA_DIR . $key . '/' . $fileTarget . '.json'), true); + $data [$fileTarget] = array_merge($dataTarget[$fileTarget], $dataSource); + if( $list === ''){ + file_put_contents(self::DATA_DIR . '/' .$key . '/' . $fileTarget . '.json', json_encode( $data ,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|LOCK_EX) ); } } } - */ - - - // Supprimer le dossier temporaire - $this->removeDir(self::TEMP_DIR . $tempFolder); - $zip->close(); - /* - if( $list !== '' ){ - $success = false; - strpos( $list, ',') === false ? $notification = 'Import impossible la page suivante doit être renommée :'.$list : $notification = 'Import impossible les pages suivantes doivent être renommées :'.$list; - } - else{ - $success = true; - $notification = 'Import réussi'; - }*/ - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'plugin', - 'state' => $success, - 'notification' => $notification - ]); } + */ - // Liste des pages ne contenant pas de module - self::$pagesList = $this->getData(['page']); - foreach(self::$pagesList as $page => $pageId) { - if ($this->getData(['page',$page,'block']) === 'bar' || - $this->getData(['page',$page,'disable']) === true || - $this->getData(['page',$page,'moduleId']) !== '') { - unset(self::$pagesList[$page]); - } + + // Supprimer le dossier temporaire + $this->removeDir(self::TEMP_DIR . $tempFolder); + $zip->close(); + /* + if( $list !== '' ){ + $success = false; + strpos( $list, ',') === false ? $notification = 'Import impossible la page suivante doit être renommée :'.$list : $notification = 'Import impossible les pages suivantes doivent être renommées :'.$list; } - + else{ + $success = true; + $notification = 'Import réussi'; + }*/ // Valeurs en sortie $this->addOutput([ - 'title' => 'Importer des données de module', - 'view' => 'dataImport' + 'redirect' => helper::baseUrl() . 'plugin', + 'state' => $success, + 'notification' => $notification ]); } + + // Liste des pages ne contenant pas de module + self::$pagesList = $this->getData(['page']); + foreach(self::$pagesList as $page => $pageId) { + if ($this->getData(['page',$page,'block']) === 'bar' || + $this->getData(['page',$page,'disable']) === true || + $this->getData(['page',$page,'moduleId']) !== '') { + unset(self::$pagesList[$page]); + } + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Importer des données de module', + 'view' => 'dataImport' + ]); } diff --git a/core/module/plugin/view/index/index.php b/core/module/plugin/view/index/index.php index 9026697a..1453ba39 100644 --- a/core/module/plugin/view/index/index.php +++ b/core/module/plugin/view/index/index.php @@ -15,20 +15,13 @@ 'help' => 'Consulter l\'aide en ligne' ]); ?> -
+
helper::baseUrl() . 'plugin/store', 'value' => template::ico('shopping-basket'), - "help" => 'Lister le catalogue en ligne' + "help" => 'Catalogue de modules en ligne' ]); ?> -
-
- helper::baseUrl() . 'plugin/upload', - 'value' => template::ico('plus'), - "help" => 'Ajouter à partir d\'une archive ZIP' - ]); ?> -
+

Suppression des modules orphelins

@@ -39,8 +32,19 @@ -

Sauvegarde des données des modules installés

- +
+
+

Sauvegarde des données des modules installés

+
+
+ helper::baseUrl() . 'dataImport', + 'value' => template::ico('upload'), + "help" => 'Importer des données de module' + ]); ?> +
+
+ diff --git a/core/module/plugin/view/store/store.php b/core/module/plugin/view/store/store.php index 154bc4c7..9aabc4a0 100644 --- a/core/module/plugin/view/store/store.php +++ b/core/module/plugin/view/store/store.php @@ -6,6 +6,13 @@ 'value' => template::ico('left') ]); ?> +
+ helper::baseUrl() . 'plugin/upload', + 'value' => template::ico('plus'), + "help" => 'Importer depuis une archive ZIP' + ]); ?> +
diff --git a/truc b/truc deleted file mode 100644 index ed62dafb..00000000 --- a/truc +++ /dev/null @@ -1 +0,0 @@ -{"config":{"previewLength":"100","resultHideContent":"","placeHolder":"Un ou plusieurs mots-cl\u00e9s s\u00e9par\u00e9s par un espace ou par +","submitText":"Rechercher","versionData":"2.2"},"theme":{"keywordColor":"rgba(229, 229, 1, 1)","style":"site\/data\/search\/recherche\/theme.css"}} \ No newline at end of file