eZ Community » Forums » Developer » More than one main node - check
expandshrink

More than one main node - check

More than one main node - check

Friday 17 February 2012 1:39:43 pm - 2 replies

Hi,

yes, I know, it must be impossible to have more than one main_node. But we have one installation where some objects have more than one.

Here is a query for a quick check, if your installation is also affected...

 SELECT 
            contentobject_id, 
            node_id, 
            count(*) counter,
            parent_node_id
        FROM 
            ezcontentobject_tree 
        WHERE 
            main_node_id = node_id 
        GROUP BY 
            contentobject_id HAVING counter > 1 
        ORDER BY 
            contentobject_id DESC

Friday 17 February 2012 1:46:32 pm

It happened to me few times too. 

Thanks for the SQL happy.gif Emoticon

Friday 17 February 2012 2:04:53 pm

Hi,

there are 2 ways to repair it:

a) Set the main_node in the backend

b) Do it with a script:

 # check if there are more than one mainnode
$db = eZDB::instance();
$sql = "SELECT 
            contentobject_id, 
            node_id, 
            count(*) counter,
            parent_node_id
        FROM 
            ezcontentobject_tree 
        WHERE 
            main_node_id = node_id 
        GROUP BY 
            contentobject_id having counter > 1 
        ORDER BY 
            contentobject_id desc";
$result = $db->arrayQuery( $sql );
 
foreach ( $result as $item )
{
    $obj = eZContentObject::fetch( $item['contentobject_id'] );
    if ( !$isQuiet )
    {
        $cli->output( "Object " . $item['contentobject_id'] . " - '" . $obj->attribute( 'name' ) . "' - has more than one main node. Fixing this. New main_node: " . $item['node_id'] );
    }
    $mainNodeID = $item['node_id'];
    $parentNodeID = $item['parent_node_id'];
    eZContentObjectTreeNode::updateMainNodeID( $mainNodeID, $item['contentobject_id'], false, $parentNodeID, true );
}
expandshrink

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

36 542 Users on board!

Forums menu