admin init command

This commit is contained in:
2024-09-23 17:03:42 +03:00
parent 0f05bc2391
commit a48088581f
25 changed files with 376 additions and 34 deletions

View File

@ -0,0 +1,94 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\modules\menu\service\MenuService;
use kernel\modules\option\service\OptionService;
use kernel\services\MigrationService;
class AdminConsoleController extends ConsoleController
{
protected MigrationService $migrationService;
protected OptionService $optionService;
public MenuService $menuService;
public function __construct()
{
parent::__construct();
$this->migrationService = new MigrationService();
$this->optionService = new OptionService();
$this->menuService = new MenuService();
}
/**
* @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",
value: "/home/kavlar/php/MicroFrameWork/kernel/admin_themes/default",
label: "Активная тема админпанели"
);
$this->out->r("create option active_admin_theme", "green");
$this->optionService->createFromParams(
key: "module_paths",
value: "{\"paths\": [\"{KERNEL_MODULES}\", \"{APP}/modules\"]}",
label: "Пути к модулям "
);
$this->out->r("create option module_paths", "green");
$this->optionService->createFromParams(
key: "active_modules",
value: "{\"modules\":[\"admin_themes\"]}",
label: "Активные модули"
);
$this->out->r("create option active_modules", "green");
$this->menuService->createItem([
"label" => "Модули",
"url" => "/admin",
"slug" => "module",
]);
$this->out->r("create item menu module", "green");
$this->menuService->createItem([
"label" => "Настройки",
"url" => "/admin/settings",
"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");
}
}

View File

@ -19,6 +19,7 @@ use kernel\services\ModuleService;
class MigrationController extends ConsoleController
{
protected ModuleService $moduleService;
public function __construct()
{
parent::__construct();
@ -35,8 +36,7 @@ class MigrationController extends ConsoleController
$table->integer('batch');
});
$this->out->r("Success", 'green');
}
catch (\Exception $e){
} catch (\Exception $e) {
$this->out->r($e->getMessage(), 'red');
}
}
@ -60,7 +60,7 @@ class MigrationController extends ConsoleController
);
$this->out->r(basename($res) . " created", 'green');
} catch (\Exception $e) {
$this->out->r('Message: ' .$e->getMessage(), 'red');
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
@ -71,15 +71,18 @@ class MigrationController extends ConsoleController
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
//$migrationPaths = [ROOT_DIR . '/migrations'];
if (\kernel\App::$db->schema->hasTable('option')) {
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
} else {
$migrationPaths = [ROOT_DIR . '/migrations'];
}
$res = $m->run($migrationPaths);
foreach ($res as $re){
foreach ($res as $re) {
$this->out->r(basename($re), 'green');
}
}
catch (\Exception $e){
$this->out->r('Message: ' .$e->getMessage(), 'red');
} catch (\Exception $e) {
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
@ -94,12 +97,11 @@ class MigrationController extends ConsoleController
$migrationPaths = [ROOT_DIR . '/migrations'];
$res = $m->rollback($migrationPaths, ['step' => $step]);
print_r($step);
foreach ($res as $re){
foreach ($res as $re) {
$this->out->r(basename($re), 'green');
}
}
catch (\Exception $e){
$this->out->r('Message: ' .$e->getMessage(), 'red');
} catch (\Exception $e) {
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
}

View File

@ -17,3 +17,7 @@ App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCol
App::$collector->console('uninstall', [\kernel\console\controllers\AdminThemeController::class, 'actionUninstallTheme']);
});
App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector $router){
App::$collector->console('init', [\kernel\console\controllers\AdminConsoleController::class, 'actionInit']);
});