module install/uninstall

This commit is contained in:
Билай Станислав 2024-10-08 12:16:41 +03:00
parent 9823a6ad8e
commit 720d75ee51
16 changed files with 127 additions and 148 deletions

View File

@ -4,6 +4,7 @@
"author": "ITGuild", "author": "ITGuild",
"slug": "tag", "slug": "tag",
"description": "Tags module", "description": "Tags module",
"module_path": "{APP}/modules/{slug}",
"module_class": "app\\modules\\tag\\TagModule", "module_class": "app\\modules\\tag\\TagModule",
"module_class_file": "{APP}/modules/tag/TagModule.php" "module_class_file": "{APP}/modules/tag/TagModule.php"
} }

View File

@ -1,17 +0,0 @@
<?php
//
//namespace app\tables\columns\menu;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class MenuDeleteActionColumn extends ActionColumn
//{
//
// protected string $prefix = "/delete/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
// }
//}

View File

@ -1,17 +0,0 @@
<?php
//
//namespace app\tables\columns\menu;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class MenuEditActionColumn extends ActionColumn
//{
//
// protected string $prefix = "/update/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
// }
//}

View File

@ -1,17 +0,0 @@
<?php
//
//namespace app\tables\columns\menu;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class MenuViewActionColumn extends ActionColumn
//{
//
// protected string $prefix = "/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
// }
//}

View File

@ -1,16 +0,0 @@
<?php
//
//namespace app\tables\columns\post;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class PostDeleteActionColumn extends ActionColumn
//{
// protected string $prefix = "/delete/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
// }
//}

View File

@ -1,16 +0,0 @@
<?php
//
//namespace app\tables\columns\post;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class PostEditActionColumn extends ActionColumn
//{
// protected string $prefix = "/update/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
// }
//}

View File

@ -1,16 +0,0 @@
<?php
//
//namespace app\tables\columns\post;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class PostViewActionColumn extends actionColumn
//{
// protected string $prefix = "/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
// }
//}

View File

@ -1,16 +0,0 @@
<?php
//
//namespace app\tables\columns\user;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class UserDeleteActionColumn extends ActionColumn
//{
// protected string $prefix = "/delete/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
// }
//}

View File

@ -1,16 +0,0 @@
<?php
//
//namespace app\tables\columns\user;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class UserEditActionColumn extends ActionColumn
//{
// protected string $prefix = "/update/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
// }
//}

View File

@ -1,16 +0,0 @@
<?php
//
//namespace app\tables\columns\user;
//
//use Itguild\Tables\ActionColumn\ActionColumn;
//
//class UserViewActionColumn extends ActionColumn
//{
// protected string $prefix = "/";
//
// public function fetch(): string
// {
// $link = $this->baseUrl . $this->prefix . $this->id;
// return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
// }
//}

View File

@ -0,0 +1,78 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\models\Option;
use ZipArchive;
use kernel\services\ModuleService;
class ModuleController extends ConsoleController
{
/**
* @throws \Exception
*/
public function actionInstallModule(): void
{
if (!isset($this->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');
}
}
}

View File

@ -21,3 +21,8 @@ App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector
App::$collector->console('init', [\kernel\console\controllers\AdminConsoleController::class, 'actionInit']); 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']);
});

View File

@ -97,7 +97,6 @@ class MenuController extends AdminController
$menuForm = new CreateMenuForm(); $menuForm = new CreateMenuForm();
$menuForm->load($_REQUEST); $menuForm->load($_REQUEST);
// Debug::dd($_REQUEST);
if (isset($_FILES['icon_file']) && $_FILES['icon_file']['error'] === UPLOAD_ERR_OK) { if (isset($_FILES['icon_file']) && $_FILES['icon_file']['error'] === UPLOAD_ERR_OK) {
$file = new FileUpload($_FILES['icon_file'], ['jpg', 'jpeg', 'png'], $_REQUEST['hashing'] ?? true); $file = new FileUpload($_FILES['icon_file'], ['jpg', 'jpeg', 'png'], $_REQUEST['hashing'] ?? true);

Binary file not shown.

View File

@ -0,0 +1,33 @@
<?php
namespace app\modules\tag;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class TagModule extends Module
{
public MenuService $menuService;
public function __construct()
{
$this->menuService = 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");
}
}

View File

@ -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"
}