Compare commits
3 Commits
378f27970e
...
11cb001cfd
Author | SHA1 | Date | |
---|---|---|---|
11cb001cfd | |||
6c1bd4a8e6 | |||
73a64ff717 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ vendor
|
|||||||
views_cache
|
views_cache
|
||||||
resources/upload
|
resources/upload
|
||||||
resources/tmp
|
resources/tmp
|
||||||
|
composer.lock
|
3294
composer.lock
generated
3294
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -46,8 +46,16 @@ class CgRouteCollector extends RouteCollector
|
|||||||
//TODO
|
//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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,8 +30,7 @@ class TagModule extends Module
|
|||||||
*/
|
*/
|
||||||
public function init(): void
|
public function init(): void
|
||||||
{
|
{
|
||||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag");
|
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");
|
||||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations/tag_entity");
|
|
||||||
|
|
||||||
$this->menuService->createItem([
|
$this->menuService->createItem([
|
||||||
"label" => "Тэги",
|
"label" => "Тэги",
|
||||||
@ -49,11 +48,17 @@ class TagModule extends Module
|
|||||||
OptionService::createFromParams("entity_tag_list", "{}", "Список тегов");
|
OptionService::createFromParams("entity_tag_list", "{}", "Список тегов");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function deactivate(): void
|
public function deactivate(): void
|
||||||
{
|
{
|
||||||
$this->menuService->removeItemBySlug("tag");
|
$this->menuService->removeItemBySlug("tag");
|
||||||
$this->menuService->removeItemBySlug("tag_settings");
|
$this->menuService->removeItemBySlug("tag_settings");
|
||||||
|
|
||||||
OptionService::removeOptionByKey("entity_tag_list");
|
OptionService::removeOptionByKey("entity_tag_list");
|
||||||
|
|
||||||
|
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tag/migrations");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formInputs(string $entity, Model $model = null): void
|
public function formInputs(string $entity, Model $model = null): void
|
||||||
|
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
|
public string $migration;
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
@ -28,4 +29,5 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
\kernel\App::$db->schema->dropIfExists('tag');
|
\kernel\App::$db->schema->dropIfExists('tag');
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
|
public string $migration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
@ -64,6 +64,11 @@ class Out
|
|||||||
echo $this->get($string, $foreground_color, $background_color) . "\n";
|
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
|
// Returns all foreground color names
|
||||||
public function getForegroundColors()
|
public function getForegroundColors()
|
||||||
{
|
{
|
||||||
|
@ -16,10 +16,23 @@ class MainController extends ConsoleController
|
|||||||
|
|
||||||
public function actionHelp(): void
|
public function actionHelp(): void
|
||||||
{
|
{
|
||||||
// Debug::dd(App::$collector->getData());
|
$routs = App::$collector->getData()->getStaticRoutes();
|
||||||
// foreach (App::$collector->getDescriptions() as $description){
|
foreach ($routs as $rout => $data){
|
||||||
// $this->out->r($description, "green");
|
$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("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
|
public string $migration;
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use kernel\App;
|
use kernel\App;
|
||||||
|
use kernel\console\controllers\MigrationController;
|
||||||
use Phroute\Phroute\RouteCollector;
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]);
|
App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]);
|
||||||
App::$collector->console("help", [\kernel\console\controllers\MainController::class, "actionHelp"]);
|
App::$collector->console("help", [\kernel\console\controllers\MainController::class, "actionHelp"]);
|
||||||
|
|
||||||
App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){
|
App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){
|
||||||
App::$collector->console('run', [\kernel\console\controllers\MigrationController::class, 'actionRun']);
|
App::$collector->console('run',
|
||||||
App::$collector->console('init', [\kernel\console\controllers\MigrationController::class, 'actionCreateMigrationTable']);
|
[MigrationController::class, 'actionRun'],
|
||||||
App::$collector->console('create', [\kernel\console\controllers\MigrationController::class, 'actionCreate']);
|
additionalInfo: ['description' => 'Запуск существующих миграций']
|
||||||
App::$collector->console('rollback', [\kernel\console\controllers\MigrationController::class, 'actionRollback']);
|
);
|
||||||
|
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){
|
App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){
|
||||||
|
@ -12,6 +12,7 @@ use kernel\models\Option;
|
|||||||
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
||||||
use kernel\modules\user\service\UserService;
|
use kernel\modules\user\service\UserService;
|
||||||
use kernel\Request;
|
use kernel\Request;
|
||||||
|
use kernel\services\MigrationService;
|
||||||
use kernel\services\ModuleService;
|
use kernel\services\ModuleService;
|
||||||
|
|
||||||
class ModuleController extends AdminController
|
class ModuleController extends AdminController
|
||||||
|
@ -5,17 +5,22 @@ namespace kernel\modules\post;
|
|||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\Module;
|
use kernel\Module;
|
||||||
use kernel\modules\menu\service\MenuService;
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
use kernel\services\MigrationService;
|
||||||
|
|
||||||
class PostModule extends Module
|
class PostModule extends Module
|
||||||
{
|
{
|
||||||
public MenuService $menuService;
|
public MenuService $menuService;
|
||||||
|
public MigrationService $migrationService;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->menuService = new MenuService();
|
$this->menuService = new MenuService();
|
||||||
|
$this->migrationService = new MigrationService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(): void
|
public function init(): void
|
||||||
{
|
{
|
||||||
|
$this->migrationService->runAtPath("{KERNEL_MODULES}/post/migrations");
|
||||||
|
|
||||||
$this->menuService->createItem([
|
$this->menuService->createItem([
|
||||||
"label" => "Посты",
|
"label" => "Посты",
|
||||||
"url" => "/admin/post",
|
"url" => "/admin/post",
|
||||||
@ -26,5 +31,6 @@ class PostModule extends Module
|
|||||||
public function deactivate(): void
|
public function deactivate(): void
|
||||||
{
|
{
|
||||||
$this->menuService->removeItemBySlug("post");
|
$this->menuService->removeItemBySlug("post");
|
||||||
|
$this->migrationService->rollbackAtPath("{KERNEL_MODULES}/post/migrations");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
|
public string $migration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
|
@ -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('Не удалось откатить миграции');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user