Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:
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();
$user = eZUser::fetch( $userID );
return \eZUser::currentUserID();
$output->writeln( $result );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.