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 0d175c2..9d0dc57 100644 Binary files a/resources/tmp/modules/tag.itguild and b/resources/tmp/modules/tag.itguild differ