From 720d75ee51cfa4871bfac514fbd39a0a386265e3 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 8 Oct 2024 12:16:41 +0300 Subject: [PATCH] module install/uninstall --- app/modules/tag/manifest.json | 1 + .../columns/menu/MenuDeleteActionColumn.php | 17 ---- .../columns/menu/MenuEditActionColumn.php | 17 ---- .../columns/menu/MenuViewActionColumn.php | 17 ---- .../columns/post/PostDeleteActionColumn.php | 16 ---- .../columns/post/PostEditActionColumn.php | 16 ---- .../columns/post/PostViewActionColumn.php | 16 ---- .../columns/user/UserDeleteActionColumn.php | 16 ---- .../columns/user/UserEditActionColumn.php | 16 ---- .../columns/user/UserViewActionColumn.php | 16 ---- .../console/controllers/ModuleController.php | 78 ++++++++++++++++++ kernel/console/routs/cli.php | 5 ++ .../menu/controllers/MenuController.php | 1 - resources/tmp/modules/tag.zip | Bin 0 -> 831 bytes resources/tmp/modules/tag/TagModule.php | 33 ++++++++ resources/tmp/modules/tag/manifest.json | 10 +++ 16 files changed, 127 insertions(+), 148 deletions(-) delete mode 100644 app/tables/columns/menu/MenuDeleteActionColumn.php delete mode 100644 app/tables/columns/menu/MenuEditActionColumn.php delete mode 100644 app/tables/columns/menu/MenuViewActionColumn.php delete mode 100644 app/tables/columns/post/PostDeleteActionColumn.php delete mode 100644 app/tables/columns/post/PostEditActionColumn.php delete mode 100644 app/tables/columns/post/PostViewActionColumn.php delete mode 100644 app/tables/columns/user/UserDeleteActionColumn.php delete mode 100644 app/tables/columns/user/UserEditActionColumn.php delete mode 100644 app/tables/columns/user/UserViewActionColumn.php create mode 100644 kernel/console/controllers/ModuleController.php create mode 100644 resources/tmp/modules/tag.zip create mode 100644 resources/tmp/modules/tag/TagModule.php create mode 100644 resources/tmp/modules/tag/manifest.json diff --git a/app/modules/tag/manifest.json b/app/modules/tag/manifest.json index 7372b40..3cbfdda 100644 --- a/app/modules/tag/manifest.json +++ b/app/modules/tag/manifest.json @@ -4,6 +4,7 @@ "author": "ITGuild", "slug": "tag", "description": "Tags module", + "module_path": "{APP}/modules/{slug}", "module_class": "app\\modules\\tag\\TagModule", "module_class_file": "{APP}/modules/tag/TagModule.php" } \ No newline at end of file diff --git a/app/tables/columns/menu/MenuDeleteActionColumn.php b/app/tables/columns/menu/MenuDeleteActionColumn.php deleted file mode 100644 index 8b70f7d..0000000 --- a/app/tables/columns/menu/MenuDeleteActionColumn.php +++ /dev/null @@ -1,17 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Удалить "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/menu/MenuEditActionColumn.php b/app/tables/columns/menu/MenuEditActionColumn.php deleted file mode 100644 index 33cded5..0000000 --- a/app/tables/columns/menu/MenuEditActionColumn.php +++ /dev/null @@ -1,17 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Редактировать "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/menu/MenuViewActionColumn.php b/app/tables/columns/menu/MenuViewActionColumn.php deleted file mode 100644 index b6b8831..0000000 --- a/app/tables/columns/menu/MenuViewActionColumn.php +++ /dev/null @@ -1,17 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Просмотр "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/post/PostDeleteActionColumn.php b/app/tables/columns/post/PostDeleteActionColumn.php deleted file mode 100644 index 3512308..0000000 --- a/app/tables/columns/post/PostDeleteActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Удалить "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/post/PostEditActionColumn.php b/app/tables/columns/post/PostEditActionColumn.php deleted file mode 100644 index 2d057ac..0000000 --- a/app/tables/columns/post/PostEditActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Редактировать "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/post/PostViewActionColumn.php b/app/tables/columns/post/PostViewActionColumn.php deleted file mode 100644 index 565856c..0000000 --- a/app/tables/columns/post/PostViewActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Просмотр "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/user/UserDeleteActionColumn.php b/app/tables/columns/user/UserDeleteActionColumn.php deleted file mode 100644 index 5d3f411..0000000 --- a/app/tables/columns/user/UserDeleteActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Удалить "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/user/UserEditActionColumn.php b/app/tables/columns/user/UserEditActionColumn.php deleted file mode 100644 index 16dc87d..0000000 --- a/app/tables/columns/user/UserEditActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Редактировать "; -// } -//} \ No newline at end of file diff --git a/app/tables/columns/user/UserViewActionColumn.php b/app/tables/columns/user/UserViewActionColumn.php deleted file mode 100644 index 60f7bae..0000000 --- a/app/tables/columns/user/UserViewActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; -// return " Просмотр "; -// } -//} \ No newline at end of file diff --git a/kernel/console/controllers/ModuleController.php b/kernel/console/controllers/ModuleController.php new file mode 100644 index 0000000..4201f5f --- /dev/null +++ b/kernel/console/controllers/ModuleController.php @@ -0,0 +1,78 @@ +argv['path'])) { + throw new \Exception('Missing module path "--path" specified'); + } + + $zip = new ZipArchive; + $tmpModuleDir = md5(time()); + $res = $zip->open(ROOT_DIR . $this->argv['path']); + if ($res === TRUE) { + $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/"; + $zip->extractTo($tmpModuleDirFull); + $zip->close(); + $this->out->r('Архив распакован', 'green'); + } else { + $this->out->r('Message: Ошибка чтения архива', 'red'); + } + + if (file_exists($tmpModuleDirFull . "manifest.json")){ + $manifestJson = getConst(file_get_contents($tmpModuleDirFull . "manifest.json")); + $manifest = Manifest::getWithVars($manifestJson); + $this->out->r('manifest.json инициализирован', 'green'); + + $fileHelper = new Files(); + $fileHelper->copy_folder($tmpModuleDirFull, $manifest['module_path']); + + $this->out->r("Удаляем временные файлы", 'green'); + $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + + $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); + } + } + + /** + * @throws \Exception + */ + public function actionUninstallModule(): 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(); + $moduleInfo = $moduleService->getModuleInfo(ROOT_DIR . $this->argv['path']); + + if ($moduleService->isActive($moduleInfo['slug'])) { + $moduleService->setActiveModule($moduleInfo['slug']); + } + + $fileHelper = new Files(); + $fileHelper->recursiveRemoveDir(ROOT_DIR . $this->argv['path']); + + $this->out->r("Модуль удален", 'green'); + } else { + var_dump($this->argv['path']); + $this->out->r("Модуль не найден", 'red'); + } + } + +} \ No newline at end of file diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php index 4c6caa2..5976755 100644 --- a/kernel/console/routs/cli.php +++ b/kernel/console/routs/cli.php @@ -21,3 +21,8 @@ App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector App::$collector->console('init', [\kernel\console\controllers\AdminConsoleController::class, 'actionInit']); }); +App::$collector->group(["prefix" => "module"], callback: function (RouteCollector $router){ + App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']); + App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']); +}); + diff --git a/kernel/modules/menu/controllers/MenuController.php b/kernel/modules/menu/controllers/MenuController.php index 2c8daf0..3d36d5d 100644 --- a/kernel/modules/menu/controllers/MenuController.php +++ b/kernel/modules/menu/controllers/MenuController.php @@ -97,7 +97,6 @@ class MenuController extends AdminController $menuForm = new CreateMenuForm(); $menuForm->load($_REQUEST); -// Debug::dd($_REQUEST); if (isset($_FILES['icon_file']) && $_FILES['icon_file']['error'] === UPLOAD_ERR_OK) { $file = new FileUpload($_FILES['icon_file'], ['jpg', 'jpeg', 'png'], $_REQUEST['hashing'] ?? true); diff --git a/resources/tmp/modules/tag.zip b/resources/tmp/modules/tag.zip new file mode 100644 index 0000000000000000000000000000000000000000..940a046a6aecbf8be89b4ca3a2cbf777f1be8135 GIT binary patch literal 831 zcmWIWW@Zs#-~hs(!5)zeP{7K_z`)C(z>u4mmzkDYT%wm%oSzpO!pp$^{60(ilUFS1 zH-Wgcf}4Sn*?0`@P?JD_bTg^SQ;f=3Ja)V^}$R<{uLyo9ojL8K|3|?U8$H`+EWRvI)9}TedOe zu9#oz^LyUXq!}fA%bq-ar=)iLXHoX7P*IPp#Jj)3-!Kam3MaGN=w`TW-{AYtX4U@g zcTbxw?QW#K+P-RW_ogWO0B?4VRPB9^(|}$Bc`E?!;TLJ8fM)^uIUA3BC`jGY3or^_I9osqd zGeo*-?(wPJT`s@IKAC%5ltCaP1JY?qjP5#};bo9GRBG*%)wZJxlt9 z$kxU;pGq9g#~B{aW<9OCdTQx0-BrWajouPA0o*)ky}_2KMuieW#Dl71atUU%=a2menuService = new MenuService(); + } + + /** + * @throws \Exception + */ + public function init(): void + { + $this->menuService->createItem([ + "label" => "Тэги", + "url" => "/admin/tag", + "slug" => "tag", + ]); + } + + public function deactivate(): void + { + $this->menuService->removeItemBySlug("tag"); + } +} \ No newline at end of file diff --git a/resources/tmp/modules/tag/manifest.json b/resources/tmp/modules/tag/manifest.json new file mode 100644 index 0000000..3cbfdda --- /dev/null +++ b/resources/tmp/modules/tag/manifest.json @@ -0,0 +1,10 @@ +{ + "name": "Tags", + "version": "0.1", + "author": "ITGuild", + "slug": "tag", + "description": "Tags module", + "module_path": "{APP}/modules/{slug}", + "module_class": "app\\modules\\tag\\TagModule", + "module_class_file": "{APP}/modules/tag/TagModule.php" +} \ No newline at end of file