Skip to content

Commit

Permalink
generate-migration: add tool option
Browse files Browse the repository at this point in the history
  • Loading branch information
seballot committed May 3, 2024
1 parent 0d18809 commit e2aa15f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion includes/migrations/README.md
Expand Up @@ -6,4 +6,8 @@ A migration is only run once

## Create a new migration

`./yeswicli generate:migration YourMigrationName`
`./yeswicli generate:migration YourMigrationName`

if it's for a specific tool/extension, for example bazar

`./yeswicli generate:migration YourMigrationName --tool=bazar`
12 changes: 10 additions & 2 deletions tools/autoupdate/commands/GenerateMigrationCommand.php
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -33,7 +35,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$migrationFileName = $timestamp . '_' . $className . '.php';
$migrationTemplate = "<?php\n\nuse YesWiki\\Core\\YesWikiMigration;\n\nclass $className extends YesWikiMigration\n{\n public function run()\n {\n\n }\n}";

$filePath = 'includes/migrations/' . $migrationFileName;
$tool = $input->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");
Expand Down

0 comments on commit e2aa15f

Please sign in to comment.