diff --git a/eZ/Bundle/EzPublishCoreBundle/Console/Application.php b/eZ/Bundle/EzPublishCoreBundle/Console/Application.php index a815551e55d..15af0125b67 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Console/Application.php +++ b/eZ/Bundle/EzPublishCoreBundle/Console/Application.php @@ -10,14 +10,10 @@ */ namespace eZ\Bundle\EzPublishCoreBundle\Console; -use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent; -use eZ\Publish\Core\MVC\Symfony\MVCEvents; use eZ\Publish\Core\MVC\Symfony\SiteAccess; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Bundle\FrameworkBundle\Console\Application as BaseApplication; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\HttpKernel\KernelInterface; /** * eZ Publish console application. @@ -25,11 +21,6 @@ */ class Application extends BaseApplication { - /** - * @var string - */ - private $siteAccessName; - public function __construct(KernelInterface $kernel) { parent::__construct($kernel); @@ -37,23 +28,4 @@ public function __construct(KernelInterface $kernel) new InputOption('--siteaccess', null, InputOption::VALUE_OPTIONAL, 'SiteAccess to use for operations. If not provided, default siteaccess will be used') ); } - - public function doRun(InputInterface $input, OutputInterface $output) - { - $this->siteAccessName = $input->getParameterOption('--siteaccess', null); - - return parent::doRun($input, $output); - } - - protected function registerCommands() - { - parent::registerCommands(); - - $container = $this->getKernel()->getContainer(); - $siteAccess = $container->get('ezpublish.siteaccess'); - $siteAccess->name = $this->siteAccessName ?: $container->getParameter('ezpublish.siteaccess.default'); - $siteAccess->matchingType = 'cli'; - $eventDispatcher = $container->get('event_dispatcher'); - $eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_CHANGE, new ScopeChangeEvent($siteAccess)); - } } diff --git a/eZ/Bundle/EzPublishCoreBundle/EventListener/ConsoleCommandListener.php b/eZ/Bundle/EzPublishCoreBundle/EventListener/ConsoleCommandListener.php new file mode 100644 index 00000000000..0ac626e8010 --- /dev/null +++ b/eZ/Bundle/EzPublishCoreBundle/EventListener/ConsoleCommandListener.php @@ -0,0 +1,74 @@ +defaultSiteAccessName = $defaultSiteAccessName; + $this->eventDispatcher = $eventDispatcher; + } + + public static function getSubscribedEvents() + { + return [ + ConsoleEvents::COMMAND => [ + ['onConsoleCommand', -1], + ], + ]; + } + + public function onConsoleCommand(ConsoleCommandEvent $event) + { + $siteAccessName = $event->getInput()->getParameterOption('--siteaccess', null); + + $this->siteAccess->name = $siteAccessName ?: $this->defaultSiteAccessName; + $this->siteAccess->matchingType = 'cli'; + + $this->eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_CHANGE, new ScopeChangeEvent($this->siteAccess)); + } + + public function setSiteAccess(SiteAccess $siteAccess = null) + { + $this->siteAccess = $siteAccess; + } +} diff --git a/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml b/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml index eebc05769d1..16174a9aaa6 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml +++ b/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml @@ -6,6 +6,7 @@ parameters: ezpublish.config.default_scope: ezsettings ezpublish.config.dynamic_setting.parser.class: eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\DynamicSettingParser ezpublish.config.complex_setting_value.resolver.class: eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ComplexSettings\ComplexSettingValueResolver + ezpublish.console_event_listener.class: eZ\Bundle\EzPublishCoreBundle\EventListener\ConsoleCommandListener ezpublish.controller.base.class: eZ\Publish\Core\MVC\Symfony\Controller\Controller ezpublish.controller.content.view.class: eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController ezpublish.controller.content.preview.class: eZ\Publish\Core\MVC\Symfony\Controller\Content\PreviewController @@ -56,6 +57,14 @@ services: ezpublish.config.complex_setting_value.resolver: class: %ezpublish.config.complex_setting_value.resolver.class% + ezpublish.console_event_listener: + class: %ezpublish.console_event_listener.class% + arguments: [%ezpublish.siteaccess.default.name%, @event_dispatcher] + calls: + - [setSiteAccess, [@ezpublish.siteaccess]] + tags: + - { name: kernel.event_subscriber } + ezpublish.controller.base: class: %ezpublish.controller.base.class% abstract: true