Forums / Developer / Using a module in command line

Using a module in command line

Author Message

Antoine W.

Friday 15 April 2005 12:56:14 am

Hello,

I have an import script that uses some classes of ez (ezdb, ezuser, eZContentClass...). This script scans my old database and imports old web pages in ez publish.

For the moment, I run it as a module of eZ publish.
I would like to have it working <b>in command line</b>, for better performances.

I think it's not possible to keep this script as a module :

php ~/ez/index.php/admin/mymodule/myview

...dont work.

So I have tried to call this script directly, including some files :

include_once( EZ_DIR."lib/ezi18n/classes/eztextcodec.php" );
include_once( EZ_DIR."lib/ezutils/classes/ezdebug.php" );
include_once( EZ_DIR. "lib/ezutils/classes/ezmodule.php" );
include_once( EZ_DIR.'lib/ezutils/classes/ezexecution.php' );
include_once( EZ_DIR.'kernel/classes/ezcontentobjecttreenode.php' );
include_once( EZ_DIR.'kernel/classes/ezcontentobject.php' );
include_once( EZ_DIR."lib/ezxml/classes/ezxml.php" );
include_once( EZ_DIR.'lib/ezlocale/classes/ezdatetime.php' );

I have no errors, but <i>ezdb</i> dont seems to work ; following lines give me an error : <b>Invalid argument supplied for foreach()</b>.

$db =& eZDB::instance();
$rows =& $db->arrayQuery( "select * from mytable" );
foreach ( $rows as $row ) echo $row['myfield'];

eZDebug::printReport(); returns nothing.

I must maybe initialize some classes before using it ? how ?

Thanks.

Ralph Ekekihl

Friday 15 April 2005 1:42:18 am

Hey!

It looks like you are not inlcuding,

include_once( "lib/ezdb/classes/ezdb.php" );

that one is needed for eZDB instance, otherwise it should work.

Then you can have a look at:

lib/ezutils/classes/ezcli.php
kernel/classes/ezscript.php

too see how you integrate the CLI scripts into ezPublish. Also have a look at the scripts in the
ezpublish/bin/php folder.

Good luck!

Contactivity B.V.
http://www.contactivity.com

Antoine W.

Monday 18 April 2005 1:55:21 am

Thanks Ralph,
Scripts in /bin/php/ helped me.
In fact, $ezdb must be instanciated as below :

$db =& eZDB::instance( $type,
                       array( 'server' => $host,
                              'user' => $user,
                              'password' => $password,
                              'database' => $database ) );