php script problem

Author Message

Aurore Hublé

Tuesday 24 October 2006 6:50:08 am

Hi everydoby,

I need to check dayly if object must be move in another folder. So, I found the corresponding php script. But, it doesn't work. It's not the first time I meet this error when I use script but in this case I don't find another way to do.
I have this code in ez publish folder :

<?php
include_once("kernel/classes/ezcontentobjecttreenode.php");
	$params = array( 'ClassFilterType' => 'include', 
				  'ClassFilterArray' => array(17,18)
			     );
	$objects =& eZContentObjectTreeNode::subTree( $params, 69 );
	echo(count($objects));
	foreach ($objects as $node)
		$node->attribute('name');
?>

I run that with the command : /opt/php/bin/php script.php

And I have the result : "0".

When I try this code in an extension, it's work very well !

I don't understand why it doesn't work in a script. Did I forget something ?

Kristof Coomans

Tuesday 24 October 2006 7:33:30 am

Hello Aurore

You need to initialize the eZ environment. Please take a look at some existing CLI scripts (which use the classes eZCLI and eZScript) in the bin/php folder.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Aurore Hublé

Tuesday 24 October 2006 7:57:31 am

Thanks I will try that !

Aurore Hublé

Tuesday 24 October 2006 8:16:40 am

In fact, I try that before posted but as I don't know what's script initializing, I cut that.
So, my code is now :

<?php
// librairies eZ publish
	include_once( 'lib/ezutils/classes/ezcli.php' );
	include_once( 'kernel/classes/ezscript.php' );

	$cli =& eZCLI::instance();
	$script = & eZScript :: instance(array("debug-message" => "", "use-session" => false, "use-modules" => true, "use-extensions" => true));
	$script->startup();

	$script->initialize();

	include_once("kernel/classes/ezcontentobjecttreenode.php");

	$params = array( 'ClassFilterType' => 'include', 
				  'ClassFilterArray' => array(17,18)
			     );
	$objects =& eZContentObjectTreeNode::subTree( $params, 69 );
	echo(count($objects));
	foreach ($objects as $node)
		$node->attribute('name');

	$script->shutdown();
?>

and always says "0"...

Kristof Coomans

Tuesday 24 October 2006 9:12:30 am

Are the nodes you want to fetch accessible by the anonymous user? Otherwise, you need to tell your script to enable the user command line options:

$script->startup();
$options = $script->getOptions( '', '', false, false, array( 'user' => true ) );
$script->initialize();

and login with the --user and --password command line options. eZScript will process these options for you and log in the user with the credentials specified.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Aurore Hublé

Wednesday 25 October 2006 12:43:37 am

Thanks for your answer.
They aren't accessible by anonymous user. I add :

$script =& eZScript::instance( array( '' , 'use-session' => false, 'use-modules' => true, 'use-extensions' => true, 'user' => true ) );

$script->startup();
$scriptOptions = $script->getOptions( '','', false, false, array( 'user' => true ) );

If I launch the script with :

 /opt/php/bin/php script.php -v -l admin -p pwdadmin

(because in the help, option --user corresponds to -l, --login)
The result is still "0".
And
If I launch the script with :

 /opt/php/bin/php script.php -v --login admin -p pwdadmin

=> script.php: option `--login' requires an argument
(It's the same with '--password')

Aurore Hublé

Wednesday 25 October 2006 1:21:56 am

I try an other thing.

include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
$user =&eZUser::loginUser("admin","pwdadmin");
if ($user)
  echo("user id: " . $user->id()p);

And login seems work. But not the fetch. :'(

Kristof Coomans

Wednesday 25 October 2006 1:55:10 am

To log in as admin from inside the script, you should use:

include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
$user = eZUser::fetchByName('admin');
$userID = $user->attribute( 'contentobject_id' );
eZUser::setCurrentlyLoggedInUser( $user, $userID );

If you use the long cli options then you have to specify their values with =

--login=admin --password=pwdadmin

Do you have any special chars in your password? You should escape them for your shell.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Aurore Hublé

Wednesday 25 October 2006 2:01:43 am

So the problem seem be on
$objects =& eZContentObjectTreeNode::subTree( false, 69);
It don't return all the node.

Result depend on user right. But in admin I must have right on all nodes !
(I don't have special character in password)

Aurore Hublé

Thursday 26 October 2006 12:13:54 am

No idea ?
I don't have this problem in an extension. If I try this code :

$objects =& eZContentObjectTreeNode::subTree( false, 69);

It's work perfectly, but in the script, it returns incomplete result. I don't found links between the returned nodes. There are in different sections and under different rights.

Kristof Coomans

Thursday 26 October 2006 1:18:49 am

Hello Aurore

Can you post the whole script you are using? Or send it by e-mail to kristof.coomans@telenet.be

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Xavier Dutoit

Thursday 26 October 2006 1:47:27 am

Hi,

Is your default siteaccess different than the one you want to use ? In that case, you have to pass as a parameter the siteaccess your want (-s<siteaccess>)

do a print_r instead of a print(count) you might have more info.

X+

http://www.sydesy.com

Aurore Hublé

Thursday 26 October 2006 2:05:06 am

Thanks for your answer.

The default siteaccess is the same I use.

The script :

<?php
	include_once( 'lib/ezutils/classes/ezcli.php' );
	include_once( 'kernel/classes/ezscript.php' );
	
	$cli =& eZCLI::instance();
	$script =& eZScript::instance( array( '',
	                                      'use-session' => false,
	                                      'use-modules' => true,
	                                      'use-extensions' => true,
					      'user' => true ) );
	$script->startup();
	$scriptOptions = $script->getOptions( '','', false, false, array( 'user' => true ) );
	$script->initialize();
	
	if ( ! $script->isInitialized() )
	{
		echo("Erreur : Impossible d'initialiser le script.");
		$script->shutdown();
		exit ();
	}
	include_once("kernel/classes/ezcontentobjecttreenode.php");
	$params = array( 'ClassFilterType' => 'include', 
					 'ClassFilterArray' => array(17,18)
			     );
	
	$objects =& eZContentObjectTreeNode::subTree( $false, 69 );
	echo(count($objects));
	foreach ( $objects as $child){
		echo($child->attribute('name'). " | " $child->attribute('class_identifier'). "\n");	
	}
?>

Launch with :
/opt/php/bin/php script.php -l admin -p pwdadmin

Result : "20
pro-distributeur | folder
Spare parts | rubrique
....
Autre | rubrique
Bloc gauche | bloc"

And if I launch the same fetch in extension or template, I have all nodes.

(print_r give the same result)

Xavier Dutoit

Thursday 26 October 2006 2:16:57 am

Salut à nouveau,

Not sure about what you want to move, but have a look at Lukasz contrib:

http://ez.no/community/contribs/cronjobs/archive

If it doesn't fit the bill 100% that might be easier to start with it and adapt it to your needs.

X+

http://www.sydesy.com

Aurore Hublé

Thursday 26 October 2006 2:29:54 am

Thanks I will try that.

Aurore Hublé

Thursday 26 October 2006 8:27:11 am

It works well on 3.7 eZ publish site but not in 3.8.
In this site, I have another problem with runcronjob, when I activate notification on approval content.
Fatal error: Call to a member function on a non-object in /.../kernel/classes/notification/handler/ezsubtree/ezsubtreehandler.php on line 123

I think the two errors are linked but if it runs on 3.7, it will run on 3.8.

Xavier Dutoit

Friday 27 October 2006 1:42:50 am

Hi,

Don't know about 3.8. Start a new thread with this specific problem, chances are higher Lucasz will jump into the problem.

X+

http://www.sydesy.com

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 18 2025 21:15:55
Script start
Timing: Jan 18 2025 21:15:55
Module start 'layout'
Timing: Jan 18 2025 21:15:55
Module start 'content'
Timing: Jan 18 2025 21:15:56
Module end 'content'
Timing: Jan 18 2025 21:15:56
Script end

Main resources:

Total runtime0.8273 sec
Peak memory usage4,096.0000 KB
Database Queries116

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 587.7969152.6094
Module start 'layout' 0.00620.0030 740.406339.4297
Module start 'content' 0.00920.8167 779.8359760.5938
Module end 'content' 0.82590.0014 1,540.429732.1875
Script end 0.8273  1,572.6172 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3752160.0002
Check MTime0.00140.1642160.0001
Mysql Total
Database connection0.00060.078110.0006
Mysqli_queries0.718186.79841160.0062
Looping result0.00100.12301140.0000
Template Total0.798696.520.3993
Template load0.00230.284020.0012
Template processing0.796296.241020.3981
Template load and register function0.00020.023010.0002
states
state_id_array0.00080.100710.0008
state_identifier_array0.00100.125220.0005
Override
Cache load0.00220.27201060.0000
Sytem overhead
Fetch class attribute can translate value0.00070.081630.0002
Fetch class attribute name0.00320.3855190.0002
XML
Image XML parsing0.00170.207730.0006
class_abstraction
Instantiating content class attribute0.00010.0068240.0000
General
dbfile0.00130.1546220.0001
String conversion0.00000.000840.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
17content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
31content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
11content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
11content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
7content/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: 79
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs