Friday 04 June 2010 8:09:02 am
Before you import any data you need to work out which eZ Publish user will be carrying it out? If you are using a template which is calling this functionality then you can pull out the current user. If you are running the script from the command line, you do not have a current user and so you may want to choose or create a specific one
For the rest of the steps of this turotial, replace the following code with that you want to use for your import (starting with this step).
Code :
/***************************** Our Functionality will go here *****************************/
Pulling in the current user is easy enough, using the static method currentUser() from within eZUser class you can pull out the user currently logged in. If nobody is logged in, the anonymous account within the CMS is used (typically if you run the function in a custom PHP Script you will be returned the anonymous user. I would recommend using the current user if the import has been triggered by an action from the user on the site.
Code :
$user = eZUser::currentUser();
You will typically want to do this if you are running a PHP script and I would recommend creating an import user for the task. You can pull out a specific user by name or email. Alternatively you can statically use an ID for the creation process but you may find these vary across your dev and live environments so I wouldn't recommend it.
Code :
$user = eZUser::fetchByName( 'Import' ); if ( !$user ) { //if no user exists let's pull out the current user: $user = eZUser::currentUser(); }
Code :
$user = eZUser::fetchByEmail( 'Import@admin.com' ); if ( !$user ) { //again, default to current user if necessary $user = eZUser::currentUser(); }