From fa68b4d34c2feca12285012613051346af5556c2 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Sun, 26 Feb 2023 16:00:00 +0100 Subject: [PATCH] [TASK] Migrate upgrade commands --- .../Command/Upgrade/UpgradeListCommand.php | 8 +++++++ .../Command/Upgrade/UpgradeRunCommand.php | 21 +++++++++++++++++++ Classes/Console/ServiceProvider.php | 16 ++++++++++++++ Configuration/Commands.php | 21 ------------------- 4 files changed, 45 insertions(+), 21 deletions(-) delete mode 100644 Configuration/Commands.php diff --git a/Classes/Console/Command/Upgrade/UpgradeListCommand.php b/Classes/Console/Command/Upgrade/UpgradeListCommand.php index 7ec48afe..e4109b39 100644 --- a/Classes/Console/Command/Upgrade/UpgradeListCommand.php +++ b/Classes/Console/Command/Upgrade/UpgradeListCommand.php @@ -21,9 +21,15 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use TYPO3\CMS\Core\Core\BootService; class UpgradeListCommand extends Command { + public function __construct(private readonly BootService $bootService) + { + parent::__construct('upgrade:list'); + } + protected function configure() { $this->setDescription('List upgrade wizards'); @@ -37,6 +43,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output): int { + $this->bootService->loadExtLocalconfDatabaseAndExtTables(); + $upgradeHandling = new UpgradeHandling(); if (!$upgradeHandling->isUpgradePrepared()) { $upgradeHandling->prepareUpgrade(); diff --git a/Classes/Console/Command/Upgrade/UpgradeRunCommand.php b/Classes/Console/Command/Upgrade/UpgradeRunCommand.php index 620410e3..d52f1c51 100644 --- a/Classes/Console/Command/Upgrade/UpgradeRunCommand.php +++ b/Classes/Console/Command/Upgrade/UpgradeRunCommand.php @@ -25,6 +25,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Style\SymfonyStyle; +use TYPO3\CMS\Core\Core\BootService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Install\Service\UpgradeWizardsService; use TYPO3\CMS\Install\Updates\DatabaseRowsUpdateWizard; @@ -33,6 +34,13 @@ class UpgradeRunCommand extends Command { private const allWizardsOrConfirmations = 'all'; + private bool $booted = false; + + public function __construct(private readonly BootService $bootService) + { + parent::__construct('upgrade:run'); + } + /** * @var UpgradeHandling */ @@ -97,6 +105,8 @@ protected function configure() protected function interact(InputInterface $input, OutputInterface $output) { + $this->ensureBooted(); + $this->upgradeHandling = new UpgradeHandling(); if (empty($input->getArgument('wizardIdentifiers'))) { $scheduledWizards = $this->upgradeHandling->listWizards()['scheduled']; @@ -125,6 +135,8 @@ protected function interact(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): int { + $this->ensureBooted(); + $this->upgradeHandling = $this->upgradeHandling ?? new UpgradeHandling(); if (!$this->upgradeHandling->isUpgradePrepared()) { $this->upgradeHandling->prepareUpgrade(); @@ -144,6 +156,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } + private function ensureBooted(): void + { + if ($this->booted) { + return; + } + $this->bootService->loadExtLocalconfDatabaseAndExtTables(); + $this->booted = true; + } + private function unpackArguments(InputInterface $input): array { $wizardsToExecute = $input->getArgument('wizardIdentifiers'); diff --git a/Classes/Console/ServiceProvider.php b/Classes/Console/ServiceProvider.php index c0a27dc6..68a942d9 100644 --- a/Classes/Console/ServiceProvider.php +++ b/Classes/Console/ServiceProvider.php @@ -19,6 +19,8 @@ use Helhum\Typo3Console\Command\Install\InstallSetupCommand; use Helhum\Typo3Console\Command\InstallTool\LockInstallToolCommand; use Helhum\Typo3Console\Command\InstallTool\UnlockInstallToolCommand; +use Helhum\Typo3Console\Command\Upgrade\UpgradeListCommand; +use Helhum\Typo3Console\Command\Upgrade\UpgradeRunCommand; use Helhum\Typo3Console\Database\Configuration\ConnectionConfiguration; use Psr\Container\ContainerInterface; use TYPO3\CMS\Core\Configuration\ConfigurationManager; @@ -26,6 +28,8 @@ use TYPO3\CMS\Core\Core\BootService; use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Package\AbstractServiceProvider; +use TYPO3\CMS\Install\Command\UpgradeWizardListCommand; +use TYPO3\CMS\Install\Command\UpgradeWizardRunCommand; class ServiceProvider extends AbstractServiceProvider { @@ -54,6 +58,8 @@ public function getFactories(): array InstallActionNeedsExecutionCommand::class => [ static::class, 'getInstallActionNeedsExecutionCommand' ], LockInstallToolCommand::class => [ static::class, 'getLockInstallToolCommand' ], UnlockInstallToolCommand::class => [ static::class, 'getUnlockInstallToolCommand' ], + UpgradeWizardListCommand::class => [ static::class, 'getUpgradeListCommand' ], + UpgradeWizardRunCommand::class => [ static::class, 'getUpgradeRunCommand' ], ]; } @@ -157,6 +163,16 @@ public static function getUnlockInstallToolCommand(): UnlockInstallToolCommand return new UnlockInstallToolCommand('install:unlock'); } + public static function getUpgradeListCommand(ContainerInterface $container): UpgradeListCommand + { + return new UpgradeListCommand($container->get(BootService::class)); + } + + public static function getUpgradeRunCommand(ContainerInterface $container): UpgradeRunCommand + { + return new UpgradeRunCommand($container->get(BootService::class)); + } + public static function configureCommands(ContainerInterface $container, CommandRegistry $commandRegistry): CommandRegistry { $commandRegistry->addLazyCommand('configuration:remove', ConfigurationRemoveCommand::class, 'Remove configuration value'); diff --git a/Configuration/Commands.php b/Configuration/Commands.php deleted file mode 100644 index 85af9f9c..00000000 --- a/Configuration/Commands.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'vendor' => 'typo3_console', - 'class' => \Helhum\Typo3Console\Command\Upgrade\UpgradeListCommand::class, - 'replace' => [ - \TYPO3\CMS\Install\Command\UpgradeWizardListCommand::class, - ], - 'runLevel' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_FULL, - ], - 'upgrade:run' => [ - 'vendor' => 'typo3_console', - 'class' => \Helhum\Typo3Console\Command\Upgrade\UpgradeRunCommand::class, - 'replace' => [ - \TYPO3\CMS\Install\Command\UpgradeWizardRunCommand::class, - ], - 'runLevel' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_FULL, - ], -];