diff options
| author | Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> | 2021-12-17 16:20:12 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2021-12-17 16:20:12 +0000 |
| commit | b0a1a7adf5203efa32661b96ecb023fef74c5d2d (patch) | |
| tree | c4641b27164f1e8d4feb2274164bed26578721af /cli/Commands/Plugins/PluginMigrate.php | |
| parent | cb0a67594116a17c78182637908c4723f37e7263 (diff) | |
CLI-Skript `studip` einführen und alte Skripte entsprechend umstellen
Diffstat (limited to 'cli/Commands/Plugins/PluginMigrate.php')
| -rw-r--r-- | cli/Commands/Plugins/PluginMigrate.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cli/Commands/Plugins/PluginMigrate.php b/cli/Commands/Plugins/PluginMigrate.php new file mode 100644 index 0000000..8bfd036 --- /dev/null +++ b/cli/Commands/Plugins/PluginMigrate.php @@ -0,0 +1,66 @@ +<?php + +namespace Studip\Cli\Commands\Plugins; + +use Studip\Cli\Commands\AbstractPluginCommand; +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; + +class PluginMigrate extends AbstractPluginCommand +{ + protected static $defaultName = 'plugin:migrate'; + + protected function configure(): void + { + $this->setDescription('Migrate a plugin.'); + $this->setHelp('This command migrates a plugin.'); + $this->addArgument('pluginname', InputArgument::REQUIRED, 'name of the plugin'); + $this->addOption('branch', 'b', InputOption::VALUE_OPTIONAL, 'branch of the migrations', '0'); + $this->addOption( + 'target', + 't', + InputOption::VALUE_REQUIRED, + 'the id number of the migration to migrate to', + null + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $pluginname = $input->getArgument('pluginname'); + $branch = $input->getOption('branch'); + $target = $input->getOption('target'); + $verbose = $input->getOption('verbose'); + + if (null !== $target) { + $target = (int) $target; + } + + $pluginManager = \PluginManager::getInstance(); + $plugin = $this->findPluginByName($pluginManager, $pluginname); + if (null === $plugin) { + $output->writeln('<error>Could not find plugin of that name.</error>'); + + return Command::FAILURE; + } + + $pluginpath = \Config::get()->PLUGINS_PATH . '/' . $plugin['path']; + + if (!is_dir($pluginpath . '/migrations')) { + $output->writeln('<comment>Could not find any migrations of that plugin.</comment>'); + + return Command::SUCCESS; + } + + // if there are migrations, migrate + $schemaVersion = new \DBSchemaVersion($plugin['name'], $branch); + $migrator = new \Migrator($pluginpath . '/migrations', $schemaVersion, $verbose); + + $migrator->migrateTo($target); + + return Command::SUCCESS; + } +} |
