Skip to content

Commit

Permalink
Merge pull request ezsystems#31 from wizhippo/EZP-24691
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 0852275 + 3c3ad2c commit a4c6288
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bundle/EventListener/LegacyKernelListener.php
Expand Up @@ -15,13 +15,28 @@
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent;

/**
* Resets eZINI when the Legacy Kernel is reset.
* Resets legacy kernel handler when used in a command.
*/
class LegacyKernelListener extends ContainerAware implements EventSubscriberInterface
{
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

public function __construct( EventDispatcherInterface $eventDispatcher )
{
$this->eventDispatcher = $eventDispatcher;
}


public static function getSubscribedEvents()
{
return [
Expand All @@ -41,7 +56,20 @@ function() {
);
}

public function onConfigScopeChange( ScopeChangeEvent $event )
{
$this->resetKernelHandler();
}

public function onConsoleCommand( ConsoleCommandEvent $event )
{
$this->resetKernelHandler();

$this->eventDispatcher->addListener( MVCEvents::CONFIG_SCOPE_CHANGE, [ $this, 'onConfigScopeChange' ], -1 );
$this->eventDispatcher->addListener( MVCEvents::CONFIG_SCOPE_RESTORE, [ $this, 'onConfigScopeChange' ], -1 );
}

private function resetKernelHandler()
{
$legacyHandlerCLI = $this->container->get( 'ezpublish_legacy.kernel_handler.cli' );
$this->container->set( 'ezpublish_legacy.kernel.lazy', null );
Expand Down
1 change: 1 addition & 0 deletions bundle/Resources/config/services.yml
Expand Up @@ -334,6 +334,7 @@ services:

ezpublish_legacy.legacy_kernel_listener:
class: %ezpublish_legacy.legacy_kernel_listener.class%
arguments: [@event_dispatcher]
calls:
- [setContainer, [@service_container]]
tags:
Expand Down

0 comments on commit a4c6288

Please sign in to comment.