eZ Community » Forums » Discussions » Finding double-published items

Wednesday 29 June 2011 11:48:00 pm - 7 replies

» Read full blog post


I had to find objects that had multiple locations for a client.  This is what I came up with:

Thursday 30 June 2011 12:53:08 pm

Just out of curiosity, did you have to find the objects which got multiple locations by error, or was it for some other reason?

Friday 01 July 2011 1:11:06 am

I was trying to track down wether smart view caching was only clearing the parent node/siblings of the main node.

Unintended double-publishing, haven't heard anything about that?

Friday 01 July 2011 1:35:04 am

Unintended double-publishing, haven't heard anything about that?

I ment like half published objects because of DB error etc. Or double published objects because of some buggy script.

Some other toughts...

- why did yu use getParentNodeIdListByContentObjectID() instead of assigned_nodes?

- for sites with a lot of content, limit and offset should be used with subTreeByNodeID() so that you can check smaller amounts of node at a time and avoid breaking of the script.

- note that by using 2 as top node id, you will miss the nodes in other parts of the node tree (images, files, users)

Saturday 02 July 2011 12:09:28 am

I think I tried assigned nodes but it didn't work for some reason... not sure why now.  But it wasn't more than a quick decision on the fly.

Yeah, limit and offset - I tend not to think of those until the script breaks.  This one hasn't broken for me yet.

Node 2 - I tend to use node 2 by default because I tend to want that content without users, media, etc. but that's why the topNodeID is a parameter.  I could see this being an easy way to see what groups users are in without having to access the user class.

Saturday 02 July 2011 12:39:32 am

I think this adresses all your points - only takes twice as long but at least it shouldn't fatal:

require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance( array(  'description' => (
                                      "finds double-published objects" ),
                                      'use-session' => false,
                                      'use-modules' => false,
                                      'use-extensions' => false ) );
$options = $script->getOptions( "", "[topNodeID]", array() );
$topNodeID = ctype_digit($options["arguments"][0]) ? $options["arguments"][0] : 1;
$params['MainNodeOnly'] = true;
$params['IgnoreVisibility'] = true;
$nodecount = eZContentObjectTreeNode::subTreeCountByNodeID( $params, $topNodeID );
for($offset=0;$offset<=$nodecount;$offset=$offset+$limit) {
        $params['Limit'] = $limit;
        $nodes = eZContentObjectTreeNode::subTreeByNodeID( $params, $topNodeID );
        foreach($nodes as $node) {
                if (count($node->object()->attribute( 'assigned_nodes' )) != 1 ) {
                        echo $node->attribute( 'path_identification_string')."\n";

Edit: don't need the session/module/extension in the script call either.

Edit: changed Object to object.

Modified on Saturday 02 July 2011 11:06:40 pm by Steven E Bailey

Saturday 02 July 2011 2:38:32 pm

Correction, "Object" should be all small caps. So like this:

if (count($node->object()->attribute( 'assigned_nodes' )) != 1 ) {

Saturday 02 July 2011 11:05:58 pm

In php user defined classes and functions are case-insensitive .  Both will work.  But whatever.


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from