From e29108f21dd97e0909e3935acf9dea34e4965f1b Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 10 Oct 2024 11:19:51 +0300 Subject: [PATCH] action update module add --- .../console/controllers/ModuleController.php | 14 ++++++ kernel/console/routs/cli.php | 1 + kernel/services/ModuleService.php | 47 ++++++++++++++++++ resources/tmp/modules/tag.itguild | Bin 6311 -> 6372 bytes 4 files changed, 62 insertions(+) diff --git a/kernel/console/controllers/ModuleController.php b/kernel/console/controllers/ModuleController.php index c586f76..539b687 100644 --- a/kernel/console/controllers/ModuleController.php +++ b/kernel/console/controllers/ModuleController.php @@ -64,4 +64,18 @@ class ModuleController extends ConsoleController } } + /** + * @throws \Exception + */ + public function actionUpdateModule(): void + { + if (!isset($this->argv['path'])) { + throw new \Exception('Missing module path "--path" specified'); + } + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $moduleService = new ModuleService(); + $moduleService->updateModule($this->argv['path']); + } + } + } \ No newline at end of file diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php index ba24d43..537a724 100644 --- a/kernel/console/routs/cli.php +++ b/kernel/console/routs/cli.php @@ -25,5 +25,6 @@ App::$collector->group(["prefix" => "module"], callback: function (RouteCollecto App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']); App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']); App::$collector->console('pack', [\kernel\console\controllers\ModuleController::class, 'actionPackModule']); + App::$collector->console('update', [\kernel\console\controllers\ModuleController::class, 'actionUpdateModule']); }); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index f639cff..8d9d228 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -172,6 +172,9 @@ class ModuleService // $out->out->r('Архив распакован', 'green'); // } else { // $this->out->r('Message: Ошибка чтения архива', 'red'); + } else { + $zip->close(); + throw new \Exception("unable to open zip archive"); } if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) { @@ -192,6 +195,7 @@ class ModuleService // $this->out->r("Удаляем временные файлы", 'green'); $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + var_dump($tmpModuleDirFull); // $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); } @@ -229,7 +233,50 @@ class ModuleService // $this->out->r("Архив создан", 'green'); $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + // $this->out->r("Временная папка удалена", 'green'); } + /** + * @throws \Exception + */ + public function updateModule(string $path): void + { + $zip = new ZipArchive; + $tmpModuleDir = md5(time()); + $res = $zip->open(ROOT_DIR . $path); + if ($res === TRUE) { + $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/"; + $zip->extractTo($tmpModuleDirFull); + $zip->close(); +// $out->out->r('Архив распакован', 'green'); +// } else { +// $this->out->r('Message: Ошибка чтения архива', 'red'); + } else { + $zip->close(); + throw new \Exception("unable to open zip archive"); + } + + if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) { + throw new \Exception('manifest.json not found'); + } + + $manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json")); + $manifest = Manifest::getWithVars($manifestJson); +// $this->out->r('manifest.json инициализирован', 'green'); + + $fileHelper = new Files(); + if (isset($manifest['kernel_module_path'])) { + $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', $manifest['kernel_module_path']); + } else { + $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']); + } + +// $this->out->r("Удаляем временные файлы", 'green'); + $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + +// $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); + + } + } \ No newline at end of file diff --git a/resources/tmp/modules/tag.itguild b/resources/tmp/modules/tag.itguild index 0d175c2eb71db89e0f89be34f5de022a98729591..9d0dc578cb2f39c4fb9b0eff0aad20c1502f6cda 100644 GIT binary patch delta 1115 zcmZ2(_{5Mmz?+#xgn@~HgJDIa*GAqYjLblK^A<*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