Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brookinsconsulting/6db5c803bbbfdf868dde to your computer and use it in GitHub Desktop.
Save brookinsconsulting/6db5c803bbbfdf868dde to your computer and use it in GitHub Desktop.
This snippet of php eZ Publish 5 (Symfony Stack) code uses the legacy kernel api to login to the user you wish to use to perform actions within eZ Publish Legacy as! Default admin user used in this example. Reference: http://share.ez.no/forums/ez-publish-5-platform/interracting-with-legacy-from-symfony-command#comment84674
<?php
protected function execute(InputInterface $input, OutputInterface $output) {
$repository = $this->getContainer()->get('ezpublish.api.repository');
$legacyKernel = $this->getContainer()->get('ezpublish_legacy.kernel');
$userID = 14; // UserID of the Default Admin User
$user = $repository->getUserService()->loadUser( $userID );
$repository->setCurrentUser( $user );
$result = $legacyKernel()->runCallback(
function () use( $userID )
{
/** Login code to run as admin user. This is required to
see past content tree permissions, sections and other limitations **/
$currentuser = eZUser::currentUser();
$currentuser->logoutCurrent();
$user = eZUser::fetch( $userID );
$user->loginCurrent();
return \eZUser::currentUserID();
}
);
$output->writeln( $result );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment