backend/kernel/console/controllers/AdminConsoleController.php

130 lines
4.3 KiB
PHP
Raw Normal View History

2024-09-23 17:03:42 +03:00
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\modules\menu\service\MenuService;
use kernel\modules\option\service\OptionService;
2024-09-24 17:22:09 +03:00
use kernel\modules\user\models\forms\CreateUserForm;
use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService;
2024-09-23 17:03:42 +03:00
use kernel\services\MigrationService;
class AdminConsoleController extends ConsoleController
{
protected MigrationService $migrationService;
protected OptionService $optionService;
2024-09-24 17:22:09 +03:00
protected MenuService $menuService;
protected UserService $userService;
2024-09-23 17:03:42 +03:00
public function __construct()
{
parent::__construct();
$this->migrationService = new MigrationService();
$this->optionService = new OptionService();
$this->menuService = new MenuService();
2024-09-24 17:22:09 +03:00
$this->userService = new UserService();
2024-09-23 17:03:42 +03:00
}
/**
* @throws \Exception
*/
public function actionInit(): void
{
$out = $this->migrationService->runAtPath("kernel/modules/menu/migrations");
$this->out->r("create menu table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/option/migrations");
$this->out->r("create option table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/user/migrations");
$this->out->r("create user table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/post/migrations");
$this->out->r("create post table", "green");
$this->optionService->createFromParams(
key: "admin_theme_paths",
value: "{\"paths\": [\"{KERNEL_ADMIN_THEMES}\", \"{APP}/admin_themes\"]}",
label: "Пути к темам админпанели"
);
$this->out->r("create option admin_theme_paths", "green");
$this->optionService->createFromParams(
key: "active_admin_theme",
2024-09-24 14:57:25 +03:00
value: "{KERNEL_ADMIN_THEMES}/default",
2024-09-23 17:03:42 +03:00
label: "Активная тема админпанели"
);
$this->out->r("create option active_admin_theme", "green");
$this->optionService->createFromParams(
key: "module_paths",
value: "{\"paths\": [\"{KERNEL_MODULES}\", \"{APP}/modules\"]}",
2024-09-24 14:57:25 +03:00
label: "Пути к модулям"
2024-09-23 17:03:42 +03:00
);
$this->out->r("create option module_paths", "green");
$this->optionService->createFromParams(
key: "active_modules",
2024-10-22 11:09:35 +03:00
value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\", \"menu\"]}",
2024-09-23 17:03:42 +03:00
label: "Активные модули"
);
$this->out->r("create option active_modules", "green");
$this->menuService->createItem([
"label" => "Модули",
"url" => "/admin",
"slug" => "module",
2024-09-24 14:57:25 +03:00
"priority" => 1,
2024-09-23 17:03:42 +03:00
]);
$this->out->r("create item menu module", "green");
2024-10-22 11:09:35 +03:00
$this->menuService->createItem([
"label" => "Пользователи",
"url" => "#",
"slug" => "user",
]);
$this->menuService->createItem([
"label" => "Список",
"url" => "/admin/user",
"slug" => "user_list",
"parent_slug" => "user",
]);
$this->menuService->createItem([
"label" => "Создать",
"url" => "/admin/user/create",
"slug" => "user_create",
"parent_slug" => "user",
]);
$this->out->r("create item menu user", "green");
2024-09-23 17:03:42 +03:00
$this->menuService->createItem([
"label" => "Настройки",
2024-10-10 22:40:09 +03:00
"url" => "#",
2024-09-23 17:03:42 +03:00
"slug" => "settings",
]);
$this->out->r("create item menu settings", "green");
$this->menuService->createItem([
"label" => "Темы админпанели",
"url" => "/admin/settings/admin-themes",
"slug" => "admin-themes",
"parent_slug" => "settings"
]);
$this->out->r("create item menu admin-themes", "green");
2024-09-24 17:22:09 +03:00
$user = new CreateUserForm();
$user->load([
'username' => 'admin',
'password' => 'ChangeMe',
'email' => 'admin@test.ru',
'role' => User::ADMIN_USER_ROLE,
]);
$this->userService->create($user);
$this->out->r("create user with username admin", "green");
2024-09-23 17:03:42 +03:00
}
}