From 4e15609322edf67a57ead39f233bde7e8e19996d Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Fri, 26 Apr 2024 09:36:11 +0200 Subject: [PATCH] generate-migration: add tool option --- includes/migrations/README.md | 6 +++++- .../autoupdate/commands/GenerateMigrationCommand.php | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/includes/migrations/README.md b/includes/migrations/README.md index cd6dfefd5..5bfe73d55 100644 --- a/includes/migrations/README.md +++ b/includes/migrations/README.md @@ -6,4 +6,8 @@ A migration is only run once ## Create a new migration -`./yeswicli generate:migration YourMigrationName` \ No newline at end of file +`./yeswicli generate:migration YourMigrationName` + +if it's for a specific tool/extension, for example bazar + +`./yeswicli generate:migration YourMigrationName --tool=bazar` \ No newline at end of file diff --git a/tools/autoupdate/commands/GenerateMigrationCommand.php b/tools/autoupdate/commands/GenerateMigrationCommand.php index 8a15b23e1..975c1e371 100644 --- a/tools/autoupdate/commands/GenerateMigrationCommand.php +++ b/tools/autoupdate/commands/GenerateMigrationCommand.php @@ -5,6 +5,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use YesWiki\Wiki; @@ -23,7 +24,8 @@ protected function configure() $this ->setName('generate:migration') ->setDescription('Create a new migration file') - ->addArgument('className', InputArgument::REQUIRED, 'The name of the migration class (CamelCase)'); + ->addArgument('className', InputArgument::REQUIRED, 'The name of the migration class (CamelCase)') + ->addOption('tool', 't', InputOption::VALUE_REQUIRED, 'The name of the tool (otherwise migration created in root folder)'); } protected function execute(InputInterface $input, OutputInterface $output) @@ -33,7 +35,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $migrationFileName = $timestamp . '_' . $className . '.php'; $migrationTemplate = "getOption('tool'); + $folderPath = (!empty($tool) ? "tools/$tool/migrations/" : 'includes/migrations/'); + if (!file_exists($folderPath)) { + mkdir($folderPath); + } + $filePath = $folderPath . $migrationFileName; + if (!file_exists($filePath)) { file_put_contents($filePath, $migrationTemplate); $output->writeln("Migration file created successfully: $filePath");