Table of contents:
A command line script is a php script which can have parameters
Cronjob and CLI scripts are similar in the way that they are both run from the command line. However, there are two important differences between CLI scripts and cronjob scripts:
Examples of CLI scripts are located in ./bin/php/*.php
Examples of Cronjob scripts are located in ./cronjobs/*.php
This is a generic example cli, command line, shell script.
#!/usr/bin/env php <?php include_once( 'kernel/classes/ezscript.php' ); include_once( 'lib/ezutils/classes/ezcli.php' ); $cli =& eZCLI::instance(); /* general script settings array with the following keys: debug-message: false debug-output: false debug-include: false debug-levels: false debug-accumulator: false debug-timing: false use-session: false use-extensions: false use-modules: false user: false, or an array with the keys 'login' and 'password' description: 'eZ publish script', site-access: false min-version: false max-version: false */ $scriptSettings = array(); $scriptSettings['description'] = 'your description of this script comes here'; $scriptSettings['use-session'] = true; $scriptSettings['use-modules'] = true; $scriptSettings['use-extensions'] = true; $script =& eZScript::instance( $scriptSettings ); $script->startup(); /* script option configuration [optionname] value indications -------------------- : -> must have a value ; -> can have a value quantity indications ---------------------- ? -> min: 0; max: 1 * -> min: 0, max: unbounded + -> min: 1, max: unbounded */ $config = ''; /* script argument configuration */ $argumentConfig = ''; /* script option help specify a hash with option identifiers as keys and their help text as values */ $optionHelp = false; /* arguments */ $arguments = false; /* standard options array( 'debug' => true, 'colors' => true, 'log' => true, 'siteaccess' => true, 'verbose' => true, 'user' => false ) */ $useStandardOptions = true; $options = $script->getOptions( $config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions ); $script->initialize(); /* $options['arguments'] is an array with all arguments passed to the script from the command line check for correct argument count: if ( count( $options['arguments'] ) != 1 ) { $script->shutdown( 1, 'wrong argument count' ); } show help: $script->showHelp(); auto-login as a specific user, without specifying a password: include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' ); $user = eZUser::fetchByName( 'admin' ); $userID = $user->attribute( 'contentobject_id' ); eZUser::setCurrentlyLoggedInUser( $user, $userID ); */ $script->shutdown( 0 ); ?>
Make sure you have enabled the loading of modules: $scriptSettings['use-modules'] = true;
Make sure you have enabled the user command line options: $useStandardOptions = array( 'user' => true );
Now use the --login and --password command line options to log in with a privileged user.
Make sure your script has UNIX line endings (LF only).
Fatal error: eZ publish did not finish its request The execution of eZ publish was abruptly ended, the debug output is present below.
You probably forgot to properly shutdown the script with $script->shutdown( 0 );
Article provided by eZpedia
All text is available under the terms of the GNU Free Documentation License
Powered by eZ Publish 6.0.2stable
Hosted by USA eZ Publish Community Partner : Brookins Consulting