Skip to content

Commit

Permalink
[TASK] Migrate upgrade commands
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed Feb 26, 2023
1 parent cd1bddf commit fa68b4d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Classes/Console/Command/Upgrade/UpgradeListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions Classes/Console/Command/Upgrade/UpgradeRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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();
Expand All @@ -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');
Expand Down
16 changes: 16 additions & 0 deletions Classes/Console/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
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;
use TYPO3\CMS\Core\Console\CommandRegistry;
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
{
Expand Down Expand Up @@ -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' ],
];
}

Expand Down Expand Up @@ -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');
Expand Down
21 changes: 0 additions & 21 deletions Configuration/Commands.php

This file was deleted.

0 comments on commit fa68b4d

Please sign in to comment.