Forums / Discussions / Finding double-published items

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

Introduction

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

» Read full blog post

Author Message

Marko Žmak

Thursday 30 June 2011 3:53:08 am

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

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Steven E. Bailey

Thursday 30 June 2011 4:11:06 pm

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?

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Marko Žmak

Thursday 30 June 2011 4:35:04 pm

"

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)

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Steven E. Bailey

Friday 01 July 2011 3:09:28 pm

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.

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Steven E. Bailey

Friday 01 July 2011 3:39:32 pm

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

 <?php
require 'autoload.php';
$limit=200;
$cli = eZCLI::instance();
$script = eZScript::instance( array(  'description' => (
                                      "finds double-published objects" ),
                                      'use-session' => false,
                                      'use-modules' => false,
                                      'use-extensions' => false ) );

$script->startup();

$options = $script->getOptions( "", "[topNodeID]", array() );
$script->initialize();

$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['Offset']=$offset;
        $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";
                }
        }
}
$script->shutdown();
?>

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

Edit: changed Object to object.

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Marko Žmak

Saturday 02 July 2011 5:38:32 am

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

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

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Steven E. Bailey

Saturday 02 July 2011 2:05:58 pm

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

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

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