eZpedia : The Free eZ Publish CMS Documentation Encyclopedia

Snippet: PHP Snippet Logging in a specific user

This is compatible with eZ Publish 4.

Code sample

The following code will login the user with the login specified by $login. It is especially useful in cronjob scripts when you need sufficient privileges.

$user = eZUser::fetchByName( $login );
$userID = $user->attribute( 'contentobject_id' );
eZUser::setCurrentlyLoggedInUser( $user, $userID );

Compatibility

In all recent versions of eZ publish the content/read policy limitation list of the current user gets cached in a global array by eZContentObjectTreeNode. When switching users, this cache isn't cleared. This issue has been reported as bug 8388 at ez.no and fixed in eZ Publish 4.1.x.

For your reference you can workaround this problem by clearing the cache yourself with the following code:

if ( isset( $GLOBALS['ezpolicylimitation_list']['content']['read'] ) )
{
    unset( $GLOBALS['ezpolicylimitation_list']['content']['read'] );
}

Article provided by eZpedia

All text is available under the terms of the GNU Free Documentation License

Powered by eZ Publish Community Project 4.2011

Hosted by Swiss eZ Publish partner YMC