Share » Learn » eZ Publish » Fetching User Objects with PHP - part 1

Fetching User Objects with PHP - part 1

Friday 24 September 2010 7:57:12 am

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Step 1: Setting up a script

Before we start we need a basic PHP script which will handle the import. Although it is just a PHP script, let's create it within a directory for cronjobs so that the script can be automated when it is finished. Please note debug is turned on in the script below so make sure to turn it off when you are happy with it.

<?php

set_time_limit ( 0 ); //ensure the script does not time out
require 'autoload.php'; //make sure relevant eZ Classes can be loaded

$cli = eZCLI::instance();//provides interface with CLI

//Setting up the script object itself:
$script = eZScript::instance( array( 'description' => "eZ Publish user export.\n\n" .
                                                      "Methods of exporting user information from eZ Publish \n" .
                                                      "\n",
                                      'use-session' => false,
                                      'use-modules' => true,
                                      'use-extensions' => true,
                                      'debug-output' => true,
                                      'debug-message' =>true
                                     
                                     ) );
$script->startup();
$script->initialize();


/*
ensuring the current user has the rights to the user information:
*/
$user = eZUser::fetchByName( 'admin' );
eZUser::setCurrentlyLoggedInUser( $user, $user->attribute( 'contentobject_id' ) );
 
/*********************
Export User Info Here
*********************/

$script->shutdown(); //stop the script

?>

For all code we create, we’ll just need to replace the comment block "Export User Info Here" with the code.

You may notice from this example we have already pulled out a user. We need to make sure the current user has the right to view user information in the CMS. By default, the anonymous account is used in the script which will not have access to this information. We therefore change the current user to be admin so that the person does have rights. We will now look at all the ways we can pull individual users out of the CMS.

 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)