This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » eZ Publish 5 Platform » Interracting with legacy from symfony...

Interracting with legacy from symfony command

Interracting with legacy from symfony command

Tuesday 23 September 2014 6:10:59 pm - 2 replies


I have to run a maintenance script on an ez5/ez4 web site.

I followed the instructions given in "Creating a command line script in your bundle" to build my command class extending the Symfony ContainerAwareCommand class.

In order to execute some legacy code in the middle of my command, I used in my execute method the legacy kernel closure (as explained by Jerome in another post).

But, despite before entering the legacy kernel, I set a repository user, when I am in the legacy kernel, I still have an anonymous user.

Do you have any idea what is wrong ?



 protected function execute(InputInterface $input, OutputInterface $output) {
    $repository = $this->getContainer()->get('ezpublish.api.repository');
    $legacyKernel = $this->getContainer()->get('ezpublish_legacy.kernel');
    $user = $repository->getUserService()->loadUser(14);
    $repository->setCurrentUser( $user );
    $result = $legacyKernel()->runCallback(
        function ()  {
            return  \eZUser::currentUserID();
$output->writeln( $result );


Modified on Tuesday 23 September 2014 6:23:05 pm by Hakim Bouras

Tuesday 23 September 2014 9:20:22 pm

Hello Hakim,

I'm sorry your having trouble. The fact is you are running into the default behavior of eZ Publish Legacy!
 So everything is really OK. 

Here is what you need to do .. Use the legacy kernel api to login to the user you wish to run as!

Note: Example php code snippet moved into a gist for better readability and long term use:

This code is untested but I just used this feature to write a pure legacy cli report generation script this afternoon so it should work as designed. You need this code because the two kernels are separate in this situation.

I hope this helps !


Modified on Wednesday 24 September 2014 12:41:41 am by // Heath

Wednesday 24 September 2014 5:04:14 pm

Thanks Heath, I suspected something like that but I was not sure if I missed something.



You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from