diff --git a/src/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPass.php b/src/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPass.php deleted file mode 100644 index 8b368c32ff..0000000000 --- a/src/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPass.php +++ /dev/null @@ -1,36 +0,0 @@ -findTaggedServiceIds('console.command') as $id => $attributes) { - $definition = $container->getDefinition($id); - - $class = $definition->getClass(); - if ($class === null || !is_a($class, Command::class, true)) { - continue; - } - - $definition->addMethodCall('addOption', [ - 'siteaccess', - null, - InputOption::VALUE_OPTIONAL, - 'SiteAccess to use for operations. If not provided, default siteaccess will be used', - ]); - } - } -} diff --git a/src/bundle/Core/EventListener/ApplicationCommandListener.php b/src/bundle/Core/EventListener/ApplicationCommandListener.php new file mode 100644 index 0000000000..8941d613d4 --- /dev/null +++ b/src/bundle/Core/EventListener/ApplicationCommandListener.php @@ -0,0 +1,49 @@ + [ + ['onConsoleCommand', 256], + ], + ]; + } + + public function onConsoleCommand(ConsoleCommandEvent $event): void + { + $command = $event->getCommand(); + if ($command === null) { + return; + } + + $application = $command->getApplication(); + if ($application === null) { + return; + } + + $inputDefinition = $application->getDefinition(); + if (false === $inputDefinition->hasOption('siteaccess')) { + $inputDefinition->addOption(new InputOption( + 'siteaccess', + null, + InputOption::VALUE_OPTIONAL, + 'SiteAccess to use for operations. If not provided, default siteaccess will be used', + )); + } + } +} diff --git a/src/bundle/Core/IbexaCoreBundle.php b/src/bundle/Core/IbexaCoreBundle.php index 3a9d62d54d..3f0e76f71a 100644 --- a/src/bundle/Core/IbexaCoreBundle.php +++ b/src/bundle/Core/IbexaCoreBundle.php @@ -12,7 +12,6 @@ use Ibexa\Bundle\Core\DependencyInjection\Compiler\ChainConfigResolverPass; use Ibexa\Bundle\Core\DependencyInjection\Compiler\ChainRoutingPass; use Ibexa\Bundle\Core\DependencyInjection\Compiler\ConsoleCacheWarmupPass; -use Ibexa\Bundle\Core\DependencyInjection\Compiler\ConsoleCommandPass; use Ibexa\Bundle\Core\DependencyInjection\Compiler\EntityManagerFactoryServiceLocatorPass; use Ibexa\Bundle\Core\DependencyInjection\Compiler\FieldTypeParameterProviderRegistryPass; use Ibexa\Bundle\Core\DependencyInjection\Compiler\FragmentPass; @@ -81,7 +80,6 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new NotificationRendererPass()); $container->addCompilerPass(new ConsoleCacheWarmupPass()); $container->addCompilerPass(new SiteAccessMatcherRegistryPass()); - $container->addCompilerPass(new ConsoleCommandPass()); $container->addCompilerPass(new LazyDoctrineRepositoriesPass(), PassConfig::TYPE_BEFORE_REMOVING); $container->addCompilerPass(new EntityManagerFactoryServiceLocatorPass()); $container->addCompilerPass(new InjectEntityManagerMappingsPass()); diff --git a/src/bundle/Core/Resources/config/services.yml b/src/bundle/Core/Resources/config/services.yml index f52e5a7ff7..1d72ac28d2 100644 --- a/src/bundle/Core/Resources/config/services.yml +++ b/src/bundle/Core/Resources/config/services.yml @@ -64,6 +64,10 @@ services: Ibexa\Bundle\Core\DependencyInjection\Configuration\ComplexSettings\ComplexSettingValueResolver: class: Ibexa\Bundle\Core\DependencyInjection\Configuration\ComplexSettings\ComplexSettingValueResolver + Ibexa\Bundle\Core\EventListener\ApplicationCommandListener: + tags: + - { name: kernel.event_subscriber } + Ibexa\Bundle\Core\EventListener\ConsoleCommandListener: class: Ibexa\Bundle\Core\EventListener\ConsoleCommandListener arguments: diff --git a/tests/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPassTest.php b/tests/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPassTest.php deleted file mode 100644 index 0885ef6a12..0000000000 --- a/tests/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPassTest.php +++ /dev/null @@ -1,57 +0,0 @@ -addCompilerPass(new ConsoleCommandPass()); - } - - public function testAddSiteaccessOption(): void - { - $commandDefinition = new Definition(Command::class); - $serviceId = 'some_service_id'; - $commandDefinition->addTag('console.command'); - - $this->setDefinition($serviceId, $commandDefinition); - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - $serviceId, - 'addOption', - [ - 'siteaccess', - null, - InputOption::VALUE_OPTIONAL, - 'SiteAccess to use for operations. If not provided, default siteaccess will be used', - ] - ); - } - - public function testSkipsSiteaccessOptionOnInvokables(): void - { - $commandDefinition = new Definition(); - $serviceId = 'some_service_id'; - $commandDefinition->addTag('console.command'); - - $this->setDefinition($serviceId, $commandDefinition); - $this->compile(); - - $this->assertContainerBuilderHasService($serviceId); - } -} diff --git a/tests/integration/Core/LegacyTestContainerBuilder.php b/tests/integration/Core/LegacyTestContainerBuilder.php index fcbff57704..9aa63066f2 100644 --- a/tests/integration/Core/LegacyTestContainerBuilder.php +++ b/tests/integration/Core/LegacyTestContainerBuilder.php @@ -8,7 +8,6 @@ namespace Ibexa\Tests\Integration\Core; -use Ibexa\Bundle\Core\DependencyInjection\Compiler\ConsoleCommandPass; use Ibexa\Bundle\Core\SiteAccess\Config\ComplexConfigProcessor; use Ibexa\Contracts\Core\SiteAccess\ConfigProcessor; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; @@ -128,8 +127,6 @@ private function registerCompilerPasses(): void $this->addCompilerPass(new Compiler\Search\Legacy\CriterionFieldValueHandlerRegistryPass()); $this->addCompilerPass(new Compiler\Search\Legacy\SortClauseConverterPass()); - $this->addCompilerPass(new ConsoleCommandPass()); - // Symfony 4 makes services private by default. Test cases are not prepared for this. // This is a simple workaround to override services as public. $this->addCompilerPass(new SetAllServicesPublicPass());