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 ) );

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 07:04:02
Script start
Timing: Jan 19 2025 07:04:02
Module start 'layout'
Timing: Jan 19 2025 07:04:02
Module start 'content'
Timing: Jan 19 2025 07:04:03
Module end 'content'
Timing: Jan 19 2025 07:04:03
Script end

Main resources:

Total runtime0.9317 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 589.1563152.6250
Module start 'layout' 0.00770.0041 741.781339.4453
Module start 'content' 0.01180.9183 781.2266540.9141
Module end 'content' 0.93010.0016 1,322.140612.1641
Script end 0.9317  1,334.3047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.3784160.0002
Check MTime0.00130.1438160.0001
Mysql Total
Database connection0.00090.097610.0009
Mysqli_queries0.875193.9249570.0154
Looping result0.00060.0624550.0000
Template Total0.894396.020.4472
Template load0.00180.195420.0009
Template processing0.892595.787620.4462
Template load and register function0.00020.025110.0002
states
state_id_array0.00080.090410.0008
state_identifier_array0.00120.127620.0006
Override
Cache load0.00150.1626340.0000
Sytem overhead
Fetch class attribute can translate value0.00060.063220.0003
Fetch class attribute name0.00200.217740.0005
XML
Image XML parsing0.00190.203520.0009
class_abstraction
Instantiating content class attribute0.00000.001140.0000
General
dbfile0.00220.2345160.0001
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs