Skip to content

Commit

Permalink
Merge pull request ezsystems#1366 from wizhippo/EZP-2469
Browse files Browse the repository at this point in the history
Fix EZP-24691: Move scope change to event so legacy-bridge can build …
  • Loading branch information
lolautruche committed Aug 31, 2015
2 parents 968aa71 + 4efcc4c commit 6f29cfa
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 29 deletions.
30 changes: 1 addition & 29 deletions eZ/Bundle/EzPublishCoreBundle/Console/Application.php
Expand Up @@ -10,50 +10,22 @@
*/
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.
* Adds options specific to an eZ Publish environment, such as the siteaccess to use.
*/
class Application extends BaseApplication
{
/**
* @var string
*/
private $siteAccessName;

public function __construct(KernelInterface $kernel)
{
parent::__construct($kernel);
$this->getDefinition()->addOption(
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));
}
}
@@ -0,0 +1,74 @@
<?php

/**
* File containing the ConsoleCommandListener class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/
namespace eZ\Bundle\EzPublishCoreBundle\EventListener;

use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent;
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* ConsoleCommandListener event listener.
*/
class ConsoleCommandListener implements EventSubscriberInterface, SiteAccessAware
{
/**
* @var string
*/
private $defaultSiteAccessName;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

/**
* @var
*/
private $siteAccess;

/**
* ConsoleCommandListener constructor.
*/
public function __construct($defaultSiteAccessName, EventDispatcherInterface $eventDispatcher)
{
$this->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;
}
}
9 changes: 9 additions & 0 deletions eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6f29cfa

Please sign in to comment.