From 0ae2a11ffc450cdf7ddd0711b1246dfbd049d96a Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 14:49:32 +0100 Subject: [PATCH 01/13] new script for rename template by new pluginId --- plugin_info/script_renameId.php | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugin_info/script_renameId.php diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php new file mode 100644 index 0000000..a2f6274 --- /dev/null +++ b/plugin_info/script_renameId.php @@ -0,0 +1,72 @@ +isFile()) { + $filePath = $file->getRealPath(); + $fileContents = file_get_contents($filePath); + + $lines = explode(PHP_EOL, $fileContents); + foreach ($lines as &$line) { + if (strpos($line, "include_file('core', 'plugin.template', 'js');") === false) { + $line = str_replace($oldId, $newId, $line); + } + } + $fileContents = implode(PHP_EOL, $lines); + + file_put_contents($filePath, $fileContents); + } + } +} + +function renameFiles($directory, $newId) { + $oldId = 'totoId'; + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); + + foreach ($files as $file) { + if ($file->isFile()) { + $filePath = $file->getRealPath(); + $fileName = $file->getFilename(); + + if (strpos($fileName, $oldId) !== false) { + $newFileName = str_replace($oldId, $newId, $fileName); + $newFilePath = $file->getPath() . DIRECTORY_SEPARATOR . $newFileName; + rename($filePath, $newFilePath); + } + } + } +} + +function processDirectories($directories, $newId) { + foreach ($directories as $directory) { + replacePluginIdInFiles($directory, $newId); + renameFiles($directory, $newId); + } +} + +echo "Entrez le nouvel ID du plugin : "; +$newId = trim(fgets(STDIN)); + +echo "Vous avez entré '$newId'. Confirmez-vous cette modification ? (oui/non) : "; +$confirmation = trim(fgets(STDIN)); + +$directories = [ + __DIR__ . '/../core/class', + __DIR__ . '/../desktop', + __DIR__ . '/../core/php', + __DIR__ . '/../desktop/modal', + __DIR__ . '/../desktop/php', + __DIR__ . '/../desktop/js', + __DIR__ , +]; + + +if (strtolower($confirmation) === 'oui' || strtolower($confirmation) === 'o') { + processDirectories($directories, $newId); + echo "L'ID du plugin a été remplacé et les fichiers ont été renommés avec succès.\n"; +} else { + echo "Modification annulée.\n"; +} From b06490a830ab45f559091b547343a051e6d85f4c Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 14:51:06 +0100 Subject: [PATCH 02/13] Update script_renameId.php --- plugin_info/script_renameId.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php index a2f6274..1d376d0 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/script_renameId.php @@ -1,7 +1,7 @@ Date: Wed, 18 Dec 2024 14:52:43 +0100 Subject: [PATCH 03/13] Update script_renameId.php --- plugin_info/script_renameId.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php index 1d376d0..fb496b2 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/script_renameId.php @@ -8,6 +8,10 @@ function replacePluginIdInFiles($directory, $newId) { if ($file->isFile()) { $filePath = $file->getRealPath(); $fileContents = file_get_contents($filePath); + + if ($fileName === 'script_renameId.php') { + continue; + } $lines = explode(PHP_EOL, $fileContents); foreach ($lines as &$line) { From c996452812a6d5ffc465abddcaead306f1e04486 Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 14:56:49 +0100 Subject: [PATCH 04/13] Update script_renameId.php --- plugin_info/script_renameId.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php index fb496b2..5401c13 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/script_renameId.php @@ -6,13 +6,15 @@ function replacePluginIdInFiles($directory, $newId) { foreach ($files as $file) { if ($file->isFile()) { - $filePath = $file->getRealPath(); - $fileContents = file_get_contents($filePath); - + + $fileName = $file->getFilename(); if ($fileName === 'script_renameId.php') { continue; } - + + $filePath = $file->getRealPath(); + $fileContents = file_get_contents($filePath); + $lines = explode(PHP_EOL, $fileContents); foreach ($lines as &$line) { if (strpos($line, "include_file('core', 'plugin.template', 'js');") === false) { From 4fc03424cb7e8d33e812dc9fe617c34513073963 Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 15:02:17 +0100 Subject: [PATCH 05/13] fix demaond in pluginInfo --- plugin_info/packages.json | 4 ++-- plugin_info/script_renameId.php | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin_info/packages.json b/plugin_info/packages.json index 2a143e9..77b03e1 100644 --- a/plugin_info/packages.json +++ b/plugin_info/packages.json @@ -8,13 +8,13 @@ "requests" : {"reinstall" : true} }, "npm": { - "plugins/template/ressources/demaond" : {} + "plugins/template/ressources/demond" : {} }, "composer": { "plugins/template" : {} }, "yarn": { - "plugins/template/ressources/demaond" : {} + "plugins/template/ressources/demond" : {} }, "plugin": { }, diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php index fb496b2..7e5ad94 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/script_renameId.php @@ -6,12 +6,14 @@ function replacePluginIdInFiles($directory, $newId) { foreach ($files as $file) { if ($file->isFile()) { - $filePath = $file->getRealPath(); - $fileContents = file_get_contents($filePath); - + + $fileName = $file->getFilename(); if ($fileName === 'script_renameId.php') { continue; } + + $filePath = $file->getRealPath(); + $fileContents = file_get_contents($filePath); $lines = explode(PHP_EOL, $fileContents); foreach ($lines as &$line) { From 00e28055383d1a4c5e843fd8616a56bb797d6a8b Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 15:44:21 +0100 Subject: [PATCH 06/13] add choices in script --- plugin_info/script_renameId.php | 64 +++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php index 23fd369..1983c80 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/script_renameId.php @@ -53,26 +53,68 @@ function processDirectories($directories, $newId) { } } -echo "Entrez le nouvel ID du plugin : "; +$pathInfoJson = __DIR__ . '/info.json'; +$jsonContent = file_get_contents($pathInfoJson); +$dataJson = json_decode($jsonContent, true); + + +echo "Quel est le nom de votre plugin ? "; +$namePlugin = trim(fgets(STDIN)); + + +if ($namePlugin !== '') { + $dataJson['name'] = $namePlugin; + echo "Plugin renommé.\n"; +} + +echo "Votre plugin possede t-il un démon ? (oui/non) : "; +$demonResponse = trim(fgets(STDIN)); + +if (strtolower($demonResponse) === 'oui' || strtolower($demonResponse) === 'o') { + + $dataJson['hasOwnDeamon'] = true; + echo "La prise en compte du démon est activée.\n"; +} + + +echo "Votre plugin possede t-il des dépendances ? (oui/non) : "; +$dependancyResponse = trim(fgets(STDIN)); + + + +if (strtolower($dependancyResponse) === 'oui' || strtolower($dependancyResponse) === 'o') { + + $dataJson['hasDependency'] = true; + echo "La prise en compte des dépendances est activée.\n"; +} + + +echo "Quel est l'ID du plugin : "; $newId = trim(fgets(STDIN)); echo "Vous avez entré '$newId'. Confirmez-vous cette modification ? (oui/non) : "; $confirmation = trim(fgets(STDIN)); -$directories = [ - __DIR__ . '/../core/class', - __DIR__ . '/../desktop', - __DIR__ . '/../core/php', - __DIR__ . '/../desktop/modal', - __DIR__ . '/../desktop/php', - __DIR__ . '/../desktop/js', - __DIR__ , -]; - if (strtolower($confirmation) === 'oui' || strtolower($confirmation) === 'o') { + + $dataJson['id'] = $newId; + + $directories = [ + __DIR__ . '/../core/class', + __DIR__ . '/../desktop', + __DIR__ . '/../core/php', + __DIR__ . '/../desktop/modal', + __DIR__ . '/../desktop/php', + __DIR__ . '/../desktop/js', + __DIR__ , + ]; + processDirectories($directories, $newId); echo "L'ID du plugin a été remplacé et les fichiers ont été renommés avec succès.\n"; } else { echo "Modification annulée.\n"; } + +$newJsonContent = json_encode($dataJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); +file_put_contents($pathInfoJson, $newJsonContent); From a99449e5f8b91e190d5f1abfb8c0757f64146d26 Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 16:01:14 +0100 Subject: [PATCH 07/13] Update script_renameId.php --- plugin_info/script_renameId.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin_info/script_renameId.php b/plugin_info/script_renameId.php index 1983c80..9b1b03a 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/script_renameId.php @@ -100,6 +100,11 @@ function processDirectories($directories, $newId) { $dataJson['id'] = $newId; + $dataJson['changelog_beta'] = str_replace('template', $newId, $dataJson['changelog_beta']); + $dataJson['changelog'] = str_replace('template', $newId, $dataJson['changelog']); + $dataJson['documentation_beta'] = str_replace('template', $newId, $dataJson['documentation_beta']); + $dataJson['documentation'] = str_replace('template', $newId, $dataJson['documentation']); + $directories = [ __DIR__ . '/../core/class', __DIR__ . '/../desktop', From 02abedea9d7eaed2b78ab653d49266cdd847b0db Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 16:21:03 +0100 Subject: [PATCH 08/13] change scriptName --- ...t_renameId.php => configurationHelper.php} | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) rename plugin_info/{script_renameId.php => configurationHelper.php} (66%) diff --git a/plugin_info/script_renameId.php b/plugin_info/configurationHelper.php similarity index 66% rename from plugin_info/script_renameId.php rename to plugin_info/configurationHelper.php index 9b1b03a..dac91d1 100644 --- a/plugin_info/script_renameId.php +++ b/plugin_info/configurationHelper.php @@ -8,7 +8,7 @@ function replacePluginIdInFiles($directory, $newId) { if ($file->isFile()) { $fileName = $file->getFilename(); - if ($fileName === 'script_renameId.php') { + if ($fileName === 'configurationHelper.php') { continue; } @@ -67,6 +67,81 @@ function processDirectories($directories, $newId) { echo "Plugin renommé.\n"; } +echo "Choisissez la catégorie de votre plugin :\n"; +echo "1. Securité\n"; +echo "2. Protocole Domotique\n"; +echo "3. Passereille Domotique\n"; +echo "4. Programmation\n"; +echo "5. Organisation\n"; +echo "6. Météo\n"; +echo "7. Communication\n"; +echo "8. Objets connectés\n"; +echo "9. Multimédia\n"; +echo "10. Confort\n"; +echo "11. Monitoring\n"; +echo "12. Santé\n"; +echo "13. Nature\n"; +echo "14. Automatisme\n"; +echo "15. Energie\n"; +echo "16. Autre\n"; + +$categoryChoice = trim(fgets(STDIN)); + +switch ($categoryChoice) { + case '1': + $dataJson['category'] = 'security'; + break; + case '2': + $dataJson['category'] = 'automation protocol'; + break; + case '3': + $dataJson['category'] = 'home automation protocol'; + break; + case '4': + $dataJson['category'] = 'programming'; + break; + case '5': + $dataJson['category'] = 'organization'; + break; + case '6': + $dataJson['category'] = 'weather'; + break; + case '7': + $dataJson['category'] = 'communication'; + break; + case '8': + $dataJson['category'] = 'devicecommunication'; + break; + case '9': + $dataJson['category'] = 'multimedia'; + break; + case '10': + $dataJson['category'] = 'wellness'; + break; + case '11': + $dataJson['category'] = 'monitoring'; + break; + case '12': + $dataJson['category'] = 'health'; + break; + case '13': + $dataJson['category'] = 'nature'; + break; + case '14': + $dataJson['category'] = 'automatisation'; + break; + case '15': + $dataJson['category'] = 'energy'; + break; + case '16': + $dataJson['category'] = 'other'; + break; + default: + echo "Choix invalide. La catégorie par défaut 'programming' sera utilisée.\n"; + $data['category'] = 'programming'; + break; +} + echo "Votre plugin possede t-il un démon ? (oui/non) : "; $demonResponse = trim(fgets(STDIN)); From ae68ce897e0568587ea20a2a56779ee743fbd658 Mon Sep 17 00:00:00 2001 From: "Johan .V" Date: Wed, 18 Dec 2024 16:29:59 +0100 Subject: [PATCH 09/13] remove ressources if no demon --- plugin_info/configurationHelper.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin_info/configurationHelper.php b/plugin_info/configurationHelper.php index dac91d1..154cb72 100644 --- a/plugin_info/configurationHelper.php +++ b/plugin_info/configurationHelper.php @@ -149,8 +149,16 @@ function processDirectories($directories, $newId) { $dataJson['hasOwnDeamon'] = true; echo "La prise en compte du démon est activée.\n"; -} - +} else { + echo "Suppression du repertoire démon.\n"; + $demonDirectory = __DIR__ . '/../resources'; + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($demonDirectory)); + foreach ($files as $file) { + if ($file->isFile()) { + unlink($file->getRealPath()); + } + } +} echo "Votre plugin possede t-il des dépendances ? (oui/non) : "; $dependancyResponse = trim(fgets(STDIN)); From c0b1d8678ef508c43255585e09580450b1304f5d Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 16:35:08 +0100 Subject: [PATCH 10/13] add demonConfirmation --- plugin_info/configurationHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin_info/configurationHelper.php b/plugin_info/configurationHelper.php index 154cb72..a05ab22 100644 --- a/plugin_info/configurationHelper.php +++ b/plugin_info/configurationHelper.php @@ -145,7 +145,10 @@ function processDirectories($directories, $newId) { echo "Votre plugin possede t-il un démon ? (oui/non) : "; $demonResponse = trim(fgets(STDIN)); -if (strtolower($demonResponse) === 'oui' || strtolower($demonResponse) === 'o') { +echo "Vous avez entré '$demonResponse'. Confirmez-vous cette modification ? (oui/non) : "; +$confirmationDemon = trim(fgets(STDIN)); + +if (strtolower($confirmationDemon) === 'oui' || strtolower($confirmationDemon) === 'o') { $dataJson['hasOwnDeamon'] = true; echo "La prise en compte du démon est activée.\n"; From 06dd91b414ed88cea5595ae1467fa80e07591d6d Mon Sep 17 00:00:00 2001 From: "Johan .V" Date: Wed, 18 Dec 2024 16:38:28 +0100 Subject: [PATCH 11/13] add rmdir after delete file --- plugin_info/configurationHelper.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/plugin_info/configurationHelper.php b/plugin_info/configurationHelper.php index a05ab22..7417dab 100644 --- a/plugin_info/configurationHelper.php +++ b/plugin_info/configurationHelper.php @@ -145,21 +145,29 @@ function processDirectories($directories, $newId) { echo "Votre plugin possede t-il un démon ? (oui/non) : "; $demonResponse = trim(fgets(STDIN)); -echo "Vous avez entré '$demonResponse'. Confirmez-vous cette modification ? (oui/non) : "; -$confirmationDemon = trim(fgets(STDIN)); - if (strtolower($confirmationDemon) === 'oui' || strtolower($confirmationDemon) === 'o') { $dataJson['hasOwnDeamon'] = true; echo "La prise en compte du démon est activée.\n"; } else { - echo "Suppression du repertoire démon.\n"; - $demonDirectory = __DIR__ . '/../resources'; - $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($demonDirectory)); - foreach ($files as $file) { - if ($file->isFile()) { - unlink($file->getRealPath()); + echo "Vous avez entré '$demonResponse'. Confirmez-vous cette modification ? (oui/non) : "; + $confirmationDemon = trim(fgets(STDIN)); + + if (strtolower($confirmationDemon) === 'oui' || strtolower($confirmationDemon) === 'o') { + echo "Suppression du repertoire démon.\n"; + $demonDirectory = __DIR__ . '/../resources'; + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($demonDirectory, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($files as $file) { + if ($file->isFile()) { + unlink($file->getRealPath()); + } elseif ($file->isDir()) { + rmdir($file->getRealPath()); + } } + rmdir($demonDirectory); } } From 431cd1e1c7ebb4229287a0b83e4cc7ec82d639d4 Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Wed, 18 Dec 2024 16:39:19 +0100 Subject: [PATCH 12/13] Update configurationHelper.php --- plugin_info/configurationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_info/configurationHelper.php b/plugin_info/configurationHelper.php index 7417dab..fd61c1c 100644 --- a/plugin_info/configurationHelper.php +++ b/plugin_info/configurationHelper.php @@ -145,7 +145,7 @@ function processDirectories($directories, $newId) { echo "Votre plugin possede t-il un démon ? (oui/non) : "; $demonResponse = trim(fgets(STDIN)); -if (strtolower($confirmationDemon) === 'oui' || strtolower($confirmationDemon) === 'o') { +if (strtolower($demonResponse) === 'oui' || strtolower($demonResponse) === 'o') { $dataJson['hasOwnDeamon'] = true; echo "La prise en compte du démon est activée.\n"; From f4a87c91818efe05a2005fea42779bfb4cc6dac4 Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Mon, 23 Dec 2024 10:13:07 +0100 Subject: [PATCH 13/13] change fileName for script, and add baseName variable --- ...configurationHelper.php => helperConfiguration.php} | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) rename plugin_info/{configurationHelper.php => helperConfiguration.php} (96%) diff --git a/plugin_info/configurationHelper.php b/plugin_info/helperConfiguration.php similarity index 96% rename from plugin_info/configurationHelper.php rename to plugin_info/helperConfiguration.php index fd61c1c..4388b74 100644 --- a/plugin_info/configurationHelper.php +++ b/plugin_info/helperConfiguration.php @@ -1,6 +1,11 @@ isFile()) { $fileName = $file->getFilename(); - if ($fileName === 'configurationHelper.php') { + if ($fileName === $scriptFileName) { continue; } @@ -29,6 +34,7 @@ function replacePluginIdInFiles($directory, $newId) { } function renameFiles($directory, $newId) { + global $scriptFileName; $oldId = 'template'; $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); @@ -142,6 +148,8 @@ function processDirectories($directories, $newId) { break; } +// echo "Vous avez choisir la catégorie '$categoryChoice'.\n"; + echo "Votre plugin possede t-il un démon ? (oui/non) : "; $demonResponse = trim(fgets(STDIN));