migration rollback at path, additional info routs

This commit is contained in:
Kavalar 2024-12-13 14:27:46 +03:00
parent 967bcc28b5
commit 73a64ff717
13 changed files with 156 additions and 76 deletions

132
composer.lock generated
View File

@ -137,16 +137,16 @@
}, },
{ {
"name": "craft-group/phroute", "name": "craft-group/phroute",
"version": "v2.1.2", "version": "v2.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/apuc/phroute.git", "url": "https://github.com/apuc/phroute.git",
"reference": "49180faae85e0ba3b0165901ad46e08508c81fac" "reference": "cc04353cd0fb1cc4ff73f273a5718023a767f150"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/apuc/phroute/zipball/49180faae85e0ba3b0165901ad46e08508c81fac", "url": "https://api.github.com/repos/apuc/phroute/zipball/cc04353cd0fb1cc4ff73f273a5718023a767f150",
"reference": "49180faae85e0ba3b0165901ad46e08508c81fac", "reference": "cc04353cd0fb1cc4ff73f273a5718023a767f150",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -178,9 +178,9 @@
"routing" "routing"
], ],
"support": { "support": {
"source": "https://github.com/apuc/phroute/tree/v2.1.2" "source": "https://github.com/apuc/phroute/tree/v2.1.3"
}, },
"time": "2022-12-17T18:27:33+00:00" "time": "2024-12-13T09:08:04+00:00"
}, },
{ {
"name": "doctrine/inflector", "name": "doctrine/inflector",
@ -725,16 +725,16 @@
}, },
{ {
"name": "illuminate/collections", "name": "illuminate/collections",
"version": "v11.34.2", "version": "v11.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/collections.git", "url": "https://github.com/illuminate/collections.git",
"reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1" "reference": "b8be9c0fedfc5be1524b290fed640d4b7d42c813"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/fd2103ddc121449a7926fc34a9d220e5b88183c1", "url": "https://api.github.com/repos/illuminate/collections/zipball/b8be9c0fedfc5be1524b290fed640d4b7d42c813",
"reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1", "reference": "b8be9c0fedfc5be1524b290fed640d4b7d42c813",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -754,6 +754,7 @@
}, },
"autoload": { "autoload": {
"files": [ "files": [
"functions.php",
"helpers.php" "helpers.php"
], ],
"psr-4": { "psr-4": {
@ -776,11 +777,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-27T14:51:56+00:00" "time": "2024-12-10T14:54:28+00:00"
}, },
{ {
"name": "illuminate/conditionable", "name": "illuminate/conditionable",
"version": "v11.34.2", "version": "v11.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/conditionable.git", "url": "https://github.com/illuminate/conditionable.git",
@ -826,16 +827,16 @@
}, },
{ {
"name": "illuminate/container", "name": "illuminate/container",
"version": "v11.34.2", "version": "v11.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/container.git", "url": "https://github.com/illuminate/container.git",
"reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26" "reference": "4a777578ce2388384565bf5c8e76881f0da68e54"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/container/zipball/b057b0bbb38d7c7524df1ca5c38e7318f4c64d26", "url": "https://api.github.com/repos/illuminate/container/zipball/4a777578ce2388384565bf5c8e76881f0da68e54",
"reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26", "reference": "4a777578ce2388384565bf5c8e76881f0da68e54",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -873,11 +874,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-21T20:07:31+00:00" "time": "2024-12-08T15:40:56+00:00"
}, },
{ {
"name": "illuminate/contracts", "name": "illuminate/contracts",
"version": "v11.34.2", "version": "v11.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/contracts.git", "url": "https://github.com/illuminate/contracts.git",
@ -1060,7 +1061,7 @@
}, },
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "v11.34.2", "version": "v11.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/macroable.git", "url": "https://github.com/illuminate/macroable.git",
@ -1106,16 +1107,16 @@
}, },
{ {
"name": "illuminate/support", "name": "illuminate/support",
"version": "v11.34.2", "version": "v11.35.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/support.git", "url": "https://github.com/illuminate/support.git",
"reference": "2b718a86571baed50fdc5d5748a846c2e58e07eb" "reference": "bc363403d9ed3214754a0501e33c05d2afcfd474"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/2b718a86571baed50fdc5d5748a846c2e58e07eb", "url": "https://api.github.com/repos/illuminate/support/zipball/bc363403d9ed3214754a0501e33c05d2afcfd474",
"reference": "2b718a86571baed50fdc5d5748a846c2e58e07eb", "reference": "bc363403d9ed3214754a0501e33c05d2afcfd474",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1138,11 +1139,12 @@
"spatie/once": "*" "spatie/once": "*"
}, },
"suggest": { "suggest": {
"illuminate/filesystem": "Required to use the composer class (^11.0).", "illuminate/filesystem": "Required to use the Composer class (^11.0).",
"laravel/serializable-closure": "Required to use the once function (^1.3).", "laravel/serializable-closure": "Required to use the once function (^1.3).",
"league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).", "league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).",
"league/uri": "Required to use the Uri class (^7.5.1).",
"ramsey/uuid": "Required to use Str::uuid() (^4.7).", "ramsey/uuid": "Required to use Str::uuid() (^4.7).",
"symfony/process": "Required to use the composer class (^7.0).", "symfony/process": "Required to use the Composer class (^7.0).",
"symfony/uid": "Required to use Str::ulid() (^7.0).", "symfony/uid": "Required to use Str::ulid() (^7.0).",
"symfony/var-dumper": "Required to use the dd function (^7.0).", "symfony/var-dumper": "Required to use the dd function (^7.0).",
"vlucas/phpdotenv": "Required to use the Env class and env helper (^5.6.1)." "vlucas/phpdotenv": "Required to use the Env class and env helper (^5.6.1)."
@ -1178,7 +1180,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-27T14:58:17+00:00" "time": "2024-12-11T23:23:18+00:00"
}, },
{ {
"name": "itguild/eloquent-table", "name": "itguild/eloquent-table",
@ -1217,11 +1219,11 @@
}, },
{ {
"name": "itguild/forms", "name": "itguild/forms",
"version": "0.1.5", "version": "0.1.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.itguild.info/ItGuild/forms_bundle.git", "url": "https://git.itguild.info/ItGuild/forms_bundle.git",
"reference": "45e57367d3f9571fde2b82fa2fd8126469ba6db6" "reference": "53e5fadfc1e250a397486565d30f27f3853e0559"
}, },
"require": { "require": {
"itguild/php-cg-select-v2": "^0.1.0", "itguild/php-cg-select-v2": "^0.1.0",
@ -1245,7 +1247,7 @@
"email": "apuc06@mail.ru" "email": "apuc06@mail.ru"
} }
], ],
"time": "2024-11-28T10:18:58+00:00" "time": "2024-12-09T20:06:48+00:00"
}, },
{ {
"name": "itguild/php-cg-select-v2", "name": "itguild/php-cg-select-v2",
@ -2220,16 +2222,16 @@
}, },
{ {
"name": "symfony/clock", "name": "symfony/clock",
"version": "v7.1.6", "version": "v7.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/clock.git", "url": "https://github.com/symfony/clock.git",
"reference": "97bebc53548684c17ed696bc8af016880f0f098d" "reference": "b81435fbd6648ea425d1ee96a2d8e68f4ceacd24"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/clock/zipball/97bebc53548684c17ed696bc8af016880f0f098d", "url": "https://api.github.com/repos/symfony/clock/zipball/b81435fbd6648ea425d1ee96a2d8e68f4ceacd24",
"reference": "97bebc53548684c17ed696bc8af016880f0f098d", "reference": "b81435fbd6648ea425d1ee96a2d8e68f4ceacd24",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2274,7 +2276,7 @@
"time" "time"
], ],
"support": { "support": {
"source": "https://github.com/symfony/clock/tree/v7.1.6" "source": "https://github.com/symfony/clock/tree/v7.2.0"
}, },
"funding": [ "funding": [
{ {
@ -2290,7 +2292,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-25T14:20:29+00:00" "time": "2024-09-25T14:21:43+00:00"
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
@ -2361,16 +2363,16 @@
}, },
{ {
"name": "symfony/finder", "name": "symfony/finder",
"version": "v7.1.6", "version": "v7.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/finder.git", "url": "https://github.com/symfony/finder.git",
"reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8" "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/2cb89664897be33f78c65d3d2845954c8d7a43b8", "url": "https://api.github.com/repos/symfony/finder/zipball/6de263e5868b9a137602dd1e33e4d48bfae99c49",
"reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8", "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2405,7 +2407,7 @@
"description": "Finds files and directories via an intuitive fluent interface", "description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/finder/tree/v7.1.6" "source": "https://github.com/symfony/finder/tree/v7.2.0"
}, },
"funding": [ "funding": [
{ {
@ -2421,7 +2423,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-10-01T08:31:23+00:00" "time": "2024-10-23T06:56:12+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@ -2449,8 +2451,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": { "thanks": {
"name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "name": "symfony/polyfill"
} }
}, },
"autoload": { "autoload": {
@ -2528,8 +2530,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": { "thanks": {
"name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "name": "symfony/polyfill"
} }
}, },
"autoload": { "autoload": {
@ -2602,8 +2604,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": { "thanks": {
"name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "name": "symfony/polyfill"
} }
}, },
"autoload": { "autoload": {
@ -2682,8 +2684,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": { "thanks": {
"name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "name": "symfony/polyfill"
} }
}, },
"autoload": { "autoload": {
@ -2758,8 +2760,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": { "thanks": {
"name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "name": "symfony/polyfill"
} }
}, },
"autoload": { "autoload": {
@ -2816,20 +2818,21 @@
}, },
{ {
"name": "symfony/translation", "name": "symfony/translation",
"version": "v7.1.6", "version": "v7.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/translation.git", "url": "https://github.com/symfony/translation.git",
"reference": "b9f72ab14efdb6b772f85041fa12f820dee8d55f" "reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/b9f72ab14efdb6b772f85041fa12f820dee8d55f", "url": "https://api.github.com/repos/symfony/translation/zipball/dc89e16b44048ceecc879054e5b7f38326ab6cc5",
"reference": "b9f72ab14efdb6b772f85041fa12f820dee8d55f", "reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.2", "php": ">=8.2",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/translation-contracts": "^2.5|^3.0" "symfony/translation-contracts": "^2.5|^3.0"
}, },
@ -2890,7 +2893,7 @@
"description": "Provides tools to internationalize your application", "description": "Provides tools to internationalize your application",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/translation/tree/v7.1.6" "source": "https://github.com/symfony/translation/tree/v7.2.0"
}, },
"funding": [ "funding": [
{ {
@ -2906,7 +2909,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-28T12:35:13+00:00" "time": "2024-11-12T20:47:56+00:00"
}, },
{ {
"name": "symfony/translation-contracts", "name": "symfony/translation-contracts",
@ -3038,16 +3041,16 @@
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.15.0", "version": "v3.17.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02" "reference": "677ef8da6497a03048192aeeb5aa3018e379ac71"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/2d5b3964cc21d0188633d7ddce732dc8e874db02", "url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71",
"reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02", "reference": "677ef8da6497a03048192aeeb5aa3018e379ac71",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3058,6 +3061,7 @@
"symfony/polyfill-php81": "^1.29" "symfony/polyfill-php81": "^1.29"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^2.0",
"psr/container": "^1.0|^2.0", "psr/container": "^1.0|^2.0",
"symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0" "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0"
}, },
@ -3101,7 +3105,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.15.0" "source": "https://github.com/twigphp/Twig/tree/v3.17.1"
}, },
"funding": [ "funding": [
{ {
@ -3113,7 +3117,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-11-17T15:59:19+00:00" "time": "2024-12-12T09:58:10+00:00"
}, },
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",
@ -3286,5 +3290,5 @@
"ext-zip": "*" "ext-zip": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.6.0" "plugin-api-version": "2.3.0"
} }

View File

@ -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);
} }
} }

View File

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

View File

@ -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');
} }
}; };

View File

@ -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.
*/ */

View File

@ -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()
{ {

View File

@ -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("");
}
}
} }
} }

View File

@ -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.
*/ */

View File

@ -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){

View File

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

View File

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

View File

@ -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.
*/ */

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('Не удалось откатить миграции');
}
}
} }