Forums / Developer / eZContentObjectTreeNode::subTreeByNodeID don't fetch all nodes

eZContentObjectTreeNode::subTreeByNodeID don't fetch all nodes

Author Message

Damien MARTIN

Wednesday 03 August 2011 1:58:05 am

Hi there,

I encounter a little problem with this code :

require_once( 'autoload.php' );

$params = array(

                'Limit' => 1000,
                'Depth' => 100,
                'ClassFilterType' => 'include',
                'ClassFilterArray' => array( 'actu_video' )

);
$videos = eZContentObjectTreeNode::subTreeByNodeID( $params, 2);

$cli->output( count( $videos ) );

foreach ( $videos as $video )
{

  $dm = $video->DataMap();

  $cli->output( $video->Name );

  unset( $dm );

}

It only grab 54 results but there is 143 instances of actu_video.

It looks like it only take the olders one and a very few of them.

Am I doing something wrong ?

Damien Pobel

Wednesday 03 August 2011 2:09:47 am

Hi Damien,

I see two possible reasons :

  • some "actu_video" may not be visible or may be hidden, if you want to fetch hidden nodes as well, you have to add the IgnoreVisibility => true option in the $params array
  • the anonymous user may not have the right to view those objects, to bypass the permission you can add Limitation => array() option in the $param array

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Damien MARTIN

Wednesday 03 August 2011 2:17:22 am

Hi Damien,

  • I already verified for hidden nodes, but they are all visibles.
  • All the nodes I want to fetch are visible by anonymous, because they are visible on the front office without needed to log in.

For informations, as I know it is a buggy version, the website is under eZ 4.0.0.

Damien Pobel

Wednesday 03 August 2011 2:32:07 am

eZ Publish 4.0.0 !? Oh my fucking god :-) this is the worst version ever :-/

Question: are you able to list the all actu_video objects  in a template with a fetch( content, tree ) call ? if not, I suspect that the database has some integrity issues.

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Mark Simon

Wednesday 03 August 2011 2:49:13 am

The class name "actu_video" makes me think that some or most of those objects may be located in the media section, not in the content section. This would be node id 43 and is NOT located in a subtree of node id 2.

Try this:

 eZContentObjectTreeNode::subTreeByNodeID($params, 43);

That would fetch all actu_video's from media.

Or:

eZContentObjectTreeNode::subTreeByNodeID($params, 1);

That would fetch all in the whlose system.

www.all2e.com

Damien MARTIN

Wednesday 03 August 2011 2:49:33 am

This piece of code works from the front :

{*?template charset=utf-8?*}
{def $videos = fetch(
                        content, list, 
                        hash(
                            parent_node_id, 2, 
                            depth, 100,
                            limit, 1000,
                            class_filter_type, include, 
                            class_filter_array, array('actu_video')
                            )
                    )}

Il y a {$videos|count} vidéos

And all the objects are available from the admin too.

Damien MARTIN

Wednesday 03 August 2011 2:50:37 am

"

The class name "actu_video" makes me think that some or most of those objects may be located in the media section, not in the content section. This would be node id 43 and is NOT located in a subtree of node id 2.

Try this:

<span style="color: #ff0000;">$videos</span> <span style="color: #66cc66;">=</span> eZContentObjectTreeNode<span style="color: #66cc66;">::</span><span style="color: #006600;">subTreeByNodeID</span><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">$params</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">43</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>

That would fetch all actu_video's from media.

Or:

<span style="color: #ff0000;">$videos</span> <span style="color: #66cc66;">=</span> eZContentObjectTreeNode<span style="color: #66cc66;">::</span><span style="color: #006600;">subTreeByNodeID</span><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">$params</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>

That would fetch all in the whlose system.

"

For sure, the objects are not in media.

Damien Pobel

Wednesday 03 August 2011 5:04:32 am

The fetch content tree and list use eZContentObjectTreeNode::subTreeByNodeID() internally (see eZContentFunctionCollection::fetchObjectTree()) so you can try to see what parameters are used when using the template fetch function.

However, I wonder if your issue is not related too the fact that in your script no user is logged in. Perhaps you can try to add the following lines before calling eZContentObjectTreeNode::subTreeByNodeID() :

$user = eZUser::fetch( 10 ); // 10 = anonymous, you can try 14 for admin
$user->loginCurrent();

or I also realize that your script misses the necessary initialization (with eZScript class). Instead of executing it directly, you can use ezexec.php wrapper :

php bin/php/ezexec.php path/to/your/script.php

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Damien MARTIN

Wednesday 03 August 2011 5:34:52 am

"

The fetch content tree and list use eZContentObjectTreeNode::subTreeByNodeID() internally (see eZContentFunctionCollection::fetchObjectTree()) so you can try to see what parameters are used when using the template fetch function.

However, I wonder if your issue is not related too the fact that in your script no user is logged in. Perhaps you can try to add the following lines before calling eZContentObjectTreeNode::subTreeByNodeID() :

$user = eZUser::fetch( 10 ); // 10 = anonymous, you can try 14 for admin
$user->loginCurrent();

or I also realize that your script misses the necessary initialization (with eZScript class). Instead of executing it directly, you can use ezexec.php wrapper :

php bin/php/ezexec.php path/to/your/script.php

Cheers

"

The script is runned as a cronjob : php runcronjobs.php export

I tryed to change the user. 10 or 14, it is the same result... 54 objects instead of 143...

Mark Simon

Thursday 04 August 2011 1:46:39 am

Are the actu_videos imported objects? Or also creaded with php?

I had the problem once that on an old eZ Version imported objectes did not complete the creation complete.
My Problem has been: The created objectets did not had a value in "published".

Even if they had a node (= visible in admin) the could not be fetched. Having published not set reacts like still being a draft.

So try to check the data in the database tables or the accouint of drafts.

www.all2e.com

Damien MARTIN

Thursday 04 August 2011 1:56:38 am

"

Are the actu_videos imported objects? Or also creaded with php?

I had the problem once that on an old eZ Version imported objectes did not complete the creation complete.
My Problem has been: The created objectets did not had a value in "published".

Even if they had a node (= visible in admin) the could not be fetched. Having published not set reacts like still being a draft.

So try to check the data in the database tables or the accouint of drafts.

"

Note imported,

They all have been created by hand in the administration interface...

I looked at drafts and the list is empty.

I'll take a look at the database.

Damien MARTIN

Thursday 04 August 2011 2:23:05 am

I don't know the eZ database, but I suppose that I should be able to fetch a specific node with the "ezcontentobject" table.

For a node who is not fetched : node_id = 690 ; object_id = 1232

And with the following SQL request :

SELECT * FROM ezcontentobject WHERE id = 1232

There is no results...

Is it normal ?

Mark Simon

Thursday 04 August 2011 4:16:16 am

That is not normal.

You cannot find a node in ezcontentobject, only the object itsself.
Though the Query IS correct.

SELECT * FROM ezcontentobject WHERE id = 1232

should fetch a row vor every accessible object by id = ObjectID

You can try to fetch the node.

SELECT * FROM ezcontentobject_tree WHERE id = 690

If that gets a result, with ezcontentobject_tree.contentobject_id is 1232
You database may be corrupt

www.all2e.com

Damien MARTIN

Friday 05 August 2011 2:20:55 am

SELECT * FROM ezcontentobject_tree WHERE node_id = 690

Doesn't work either...

Is there a procedure to fix a database ?