Compare commits

..

3 Commits

Author SHA1 Message Date
11cb001cfd gitignore 2024-12-13 14:31:13 +03:00
6c1bd4a8e6 rm composer lock 2024-12-13 14:30:25 +03:00
73a64ff717 migration rollback at path, additional info routs 2024-12-13 14:27:46 +03:00
14 changed files with 90 additions and 3307 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ vendor
views_cache
resources/upload
resources/tmp
composer.lock

3294
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -46,8 +46,16 @@ class CgRouteCollector extends RouteCollector
//TODO
}
public function console($route, $handler, array $filters = []): void
/**
* @param $route
* @param $handler
* @param array $filters
* @param array $additionalInfo
* @return void
*/
public function console($route, $handler, array $filters = [], array $additionalInfo = []): void
{
$this->addRoute(Route::GET, $route, $handler, $filters);
$additionalInfo['type'] = "console";
$this->addRoute(Route::GET, $route, $handler, $filters, $additionalInfo);
}
}

View File

@ -30,8 +30,7 @@ class TagModule extends Module
*/
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag");
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag_entity");
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");
$this->menuService->createItem([
"label" => "Тэги",
@ -49,11 +48,17 @@ class TagModule extends Module
OptionService::createFromParams("entity_tag_list", "{}", "Список тегов");
}
/**
* @throws \Exception
*/
public function deactivate(): void
{
$this->menuService->removeItemBySlug("tag");
$this->menuService->removeItemBySlug("tag_settings");
OptionService::removeOptionByKey("entity_tag_list");
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tag/migrations");
}
public function formInputs(string $entity, Model $model = null): void

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public string $migration;
/**
* Run the migrations.
*/
@ -28,4 +29,5 @@ return new class extends Migration
{
\kernel\App::$db->schema->dropIfExists('tag');
}
};

View File

@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public string $migration;
/**
* Run the migrations.
*/

View File

@ -64,6 +64,11 @@ class Out
echo $this->get($string, $foreground_color, $background_color) . "\n";
}
public function inLine($string, $foreground_color = null, $background_color = null): void
{
echo $this->get($string, $foreground_color, $background_color) ;
}
// Returns all foreground color names
public function getForegroundColors()
{

View File

@ -16,10 +16,23 @@ class MainController extends ConsoleController
public function actionHelp(): void
{
// Debug::dd(App::$collector->getData());
// foreach (App::$collector->getDescriptions() as $description){
// $this->out->r($description, "green");
// }
$routs = App::$collector->getData()->getStaticRoutes();
foreach ($routs as $rout => $data){
$additionalInfo = $data['GET'][3];
if (isset($additionalInfo['description']) and $additionalInfo['type'] === "console"){
$this->out->inLine($rout . " - ", "green");
$this->out->inLine($additionalInfo['description'], 'yellow');
$this->out->r("");
if (isset($additionalInfo['params'])){
foreach ($additionalInfo['params'] as $key => $param){
$this->out->inLine($key . " - ", "green");
$this->out->inLine($param, 'yellow');
$this->out->r("");
}
}
$this->out->r("");
}
}
}
}

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public string $migration;
/**
* Run the migrations.
*/

View File

@ -1,16 +1,26 @@
<?php
use kernel\App;
use kernel\console\controllers\MigrationController;
use Phroute\Phroute\RouteCollector;
App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]);
App::$collector->console("help", [\kernel\console\controllers\MainController::class, "actionHelp"]);
App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){
App::$collector->console('run', [\kernel\console\controllers\MigrationController::class, 'actionRun']);
App::$collector->console('init', [\kernel\console\controllers\MigrationController::class, 'actionCreateMigrationTable']);
App::$collector->console('create', [\kernel\console\controllers\MigrationController::class, 'actionCreate']);
App::$collector->console('rollback', [\kernel\console\controllers\MigrationController::class, 'actionRollback']);
App::$collector->console('run',
[MigrationController::class, 'actionRun'],
additionalInfo: ['description' => 'Запуск существующих миграций']
);
App::$collector->console('init',
[MigrationController::class, 'actionCreateMigrationTable'],
additionalInfo: ['description' => 'Инициализация миграций']
);
App::$collector->console('create',
[MigrationController::class, 'actionCreate'],
additionalInfo: ['description' => 'Создание миграции', 'params' => ['--name' => 'Название миграции', '--path' => 'Путь по которому будет создана миграция']]
);
App::$collector->console('rollback', [MigrationController::class, 'actionRollback']);
});
App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){

View File

@ -12,6 +12,7 @@ use kernel\models\Option;
use kernel\modules\module_shop_client\services\ModuleShopClientService;
use kernel\modules\user\service\UserService;
use kernel\Request;
use kernel\services\MigrationService;
use kernel\services\ModuleService;
class ModuleController extends AdminController

View File

@ -5,17 +5,22 @@ namespace kernel\modules\post;
use kernel\helpers\Debug;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class PostModule extends Module
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_MODULES}/post/migrations");
$this->menuService->createItem([
"label" => "Посты",
"url" => "/admin/post",
@ -26,5 +31,6 @@ class PostModule extends Module
public function deactivate(): void
{
$this->menuService->removeItemBySlug("post");
$this->migrationService->rollbackAtPath("{KERNEL_MODULES}/post/migrations");
}
}

View File

@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public string $migration;
/**
* Run the migrations.
*/

View File

@ -36,4 +36,25 @@ class MigrationService
}
}
public function rollbackAtPath(string $path): void
{
$path = getConst($path);
try {
$filesystem = new Filesystem();
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), $filesystem);
$migrationFiles = $m->getMigrationFiles($path);
foreach ($migrationFiles as $name => $migrationFile){
$migrationInstance = $filesystem->getRequire($migrationFile);
$migrationInstance->migration = $name;
$migrationInstance->down();
$dmr->delete($migrationInstance);
}
} catch (\Exception $e) {
throw new \Exception('Не удалось откатить миграции');
}
}
}