Commit 3db01f46 authored by Helmut Hummel's avatar Helmut Hummel Committed by Susanne Moog
Browse files

[BUGFIX] Fix cli command aliasing

Instead of overriding the command name, an aliases
are now set for a command.

Command names and aliases are now configured during
container compilation pass instead of runtime.

Resolves: #90450
Releases: master
Change-Id: I82dd96717e30d38387273fa2a10828906c5c46bc
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63331


Tested-by: Simon Gilli's avatarSimon Gilli <typo3@gilbertsoft.org>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Simon Gilli's avatarSimon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
parent 335697ac
......@@ -112,7 +112,7 @@ class CommandRegistry implements CommandLoaderInterface, \IteratorAggregate, Sin
$this->populateCommandsFromPackages();
foreach ($this->commands as $commandName => $command) {
if (is_string($command)) {
$command = $this->getInstance($command, $commandName);
$command = $this->getInstance($command);
}
yield $commandName => $command;
}
......@@ -129,7 +129,7 @@ class CommandRegistry implements CommandLoaderInterface, \IteratorAggregate, Sin
foreach ($this->commands as $commandName => $command) {
if ($this->commandConfigurations[$commandName]['schedulable'] ?? true) {
if (is_string($command)) {
$command = $this->getInstance($command, $commandName);
$command = $this->getInstance($command);
}
yield $commandName => $command;
}
......@@ -171,7 +171,7 @@ class CommandRegistry implements CommandLoaderInterface, \IteratorAggregate, Sin
$command = $this->commands[$identifier] ?? null;
if (is_string($command)) {
$command = $this->getInstance($command, $identifier);
$command = $this->getInstance($command);
}
return $command;
......@@ -218,7 +218,7 @@ class CommandRegistry implements CommandLoaderInterface, \IteratorAggregate, Sin
if (array_key_exists($commandName, $this->lazyCommandConfigurations)) {
// Lazy (DI managed) commands override classic commands from Configuration/Commands.php
// Skip this case to allow extensions to provide commands via DI config and to allow
// TYPO3 v9 backwards compatibile confguration via Configuration/Commands.php.
// TYPO3 v9 backwards compatible configuration via Configuration/Commands.php.
// Note: Also the deprecation error is skipped on-demand as the extension has been
// adapted and the configuration will be ignored as of TYPO3 v11.
continue;
......@@ -242,26 +242,18 @@ class CommandRegistry implements CommandLoaderInterface, \IteratorAggregate, Sin
}
}
protected function getInstance(string $class, string $commandName): Command
protected function getInstance(string $class): Command
{
$command = $this->container->get($class);
if ($command instanceof Command) {
$command->setName($commandName);
return $command;
}
throw new \InvalidArgumentException('Registered console command class ' . get_class($command) . ' does not inherit from ' . Command::class, 1567966448);
return $this->container->get($class);
}
/**
* @internal
*/
public function addLazyCommand(string $commandName, string $serviceName, bool $alias = false, bool $schedulable = true): void
public function addLazyCommand(string $commandName, string $serviceName, bool $schedulable = true): void
{
$this->lazyCommandConfigurations[$commandName] = [
'class' => $serviceName,
'alias' => $alias,
'schedulable' => $schedulable,
];
}
......
......@@ -47,20 +47,29 @@ final class ConsoleCommandPass implements CompilerPassInterface
return;
}
$unorderedEventListeners = [];
foreach ($container->findTaggedServiceIds($this->tagName) as $serviceName => $tags) {
$container->findDefinition($serviceName)->setPublic(true);
$commandServiceDefinition = $container->findDefinition($serviceName)->setPublic(true);
$commandName = null;
$aliases = [];
foreach ($tags as $attributes) {
if (!isset($attributes['command'])) {
continue;
}
$commandRegistryDefinition->addMethodCall('addLazyCommand', [
$attributes['command'],
$serviceName,
(bool)($attributes['alias'] ?? false),
(bool)($attributes['schedulable'] ?? true)
]);
$isAlias = isset($commandName) || ($attributes['alias'] ?? false);
if (!$isAlias) {
$commandName = $attributes['command'];
} else {
$aliases[] = $attributes['command'];
}
}
$commandServiceDefinition->addMethodCall('setName', [$commandName]);
if ($aliases) {
$commandServiceDefinition->addMethodCall('setAliases', [$aliases]);
}
}
}
......
......@@ -115,17 +115,17 @@ class ServiceProvider extends AbstractServiceProvider
public static function getLanguagePackCommand(ContainerInterface $container): Command\LanguagePackCommand
{
return new Command\LanguagePackCommand;
return new Command\LanguagePackCommand('language:update');
}
public static function getUpgradeWizardRunCommand(ContainerInterface $container): Command\UpgradeWizardRunCommand
{
return new Command\UpgradeWizardRunCommand;
return new Command\UpgradeWizardRunCommand('upgrade:run');
}
public static function getUpgradeWizardListCommand(ContainerInterface $container): Command\UpgradeWizardListCommand
{
return new Command\UpgradeWizardListCommand;
return new Command\UpgradeWizardListCommand('upgrade:list');
}
public static function configureCommands(ContainerInterface $container, CommandRegistry $commandRegistry): CommandRegistry
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment