Author Topic

Gabriele Francescotto

Thursday 04 February 2010 5:15:11 am

Comment56915

Hi,

I've been faced a similar problem, in particular importing contents using the data_import estension. If the procedure brutallystops for some reason, or if you decide to interrupt the import script, objects and attributes are genereted into the database, but not the respective node (ezcontentobject_tree).

I've extended Jonny's script, but I thank a lot the eZ guys if they could take a look.

$arrayResult3 = $db->arrayQuery( "SELECT id, name FROM ezcontentobject" );

$count = 0;
$message = "Check nodes' consistency"."\n";
$cli->output( $cli->stylize( 'cyan', $message ), false );
foreach( $arrayResult3 as $item) {

        $hasNode = $db->arrayQuery( "SELECT contentobject_id FROM ezcontentobject_tree WHERE contentobject_id = " . $item['id'] );
        if ( empty( $hasNode ) ) {
                $count++;
        //      echo "The node does not exist for the object: " . $item['name'] . ", ID " . $item['id'] . "\n";
        }
}
$message = "Check completed. Affected objects:" . $count ."\n";
$cli->output( $cli->stylize( 'cyan', $message ), false );

if ( $doUpdate ) {
    foreach( $arrayResult3 as $item) {
        $hasNode = $db->arrayQuery( "SELECT contentobject_id FROM ezcontentobject_tree WHERE contentobject_id = " . $item['id'] );
        if ( empty( $hasNode ) ) {
                $message = "The node does not exist for the object: " . $item['name'] . ", ID " . $item['id'] . "\n";
                $cli->output( $cli->stylize( 'cyan', $message ), false );
                $db->query( "DELETE FROM ezcontentobject WHERE ezcontentobject.id = " . $item['id'] );
                echo "Object removed; ";
                $cli->output( $cli->stylize( 'cyan', $message ), false );
                $db->query( "DELETE FROM ezcontentobject_name WHERE ezcontentobject.id = " . $item['id'] );
                $message = "Object name removed; ";
                $cli->output( $cli->stylize( 'cyan', $message ), false );
         //     $db->query( "DELETE FROM ezcontentobject_link WHERE ezcontentobject.id = " . $item['id'] );
        //      $message = "Object links removed; ";
        //      $cli->output( $cli->stylize( 'cyan', $message ), false );
                $db->query( "DELETE FROM ezcontentobject_version WHERE ezcontentobject.id = " . $item['id'] );
                $message = "Object versions removed; ";
                $cli->output( $cli->stylize( 'cyan', $message ), false );
                $db->query( "DELETE FROM ezcontentobject_attribute WHERE ezcontentobject.id = " . $item['id'] );
                $message = "Object attributes removed" . "\n";
                $cli->output( $cli->stylize( 'cyan', $message ), false );
        }
     }
}
$message = "Corrupted elements have been removed from the database."\n";
$cli->output( $cli->stylize( 'cyan', $message ), false );

OpenContent [free software solutions]
via Verdi 19, 38100 Trento (TN) Italy
www.opencontent.it
skype : gabricocek1
twitter: gabricocek