Last active
September 24, 2015 10:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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