Fetch and delete all objects based on a class

Author Message

Yngve Bergheim

Tuesday 25 April 2006 6:45:47 am

I want to fetch and delete all RSS objects. The code below works, the only problem is that most of my objects are not in the node tree. I added $object->purge() after running only $node->remove() several times, not realizing that the latter only removed the object from the tree structure, not deleting the object.

How do I fetch all objects without using eZContentObjectTreeNode?

include_once( "lib/ezutils/classes/ezextension.php" );
include_once( "lib/ezutils/classes/ezmodule.php" );
include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );
include_once( "kernel/classes/ezcontentobjecttreenode.php" );


/*
* Config start
*/

// Types of objects to delete
$filerArray = array('rss_link');

// Time to delete
$deleteAfterThisDate  = mktime (0,0,0,date("m")  ,date("d")-7,date("Y"));

/*
* Config end
*/


// Get top node
$node =& eZContentObjectTreeNode::fetch(2);

// Find all objects in the filterArray
$subTree =& $node->subTree( array( 
	'Limit' => 100,
	'ClassFilterType' => 'include',
    'ClassFilterArray' => $filerArray ) );

foreach ( $subTree as $node )
{
    $object =& $node->attribute( 'object' );
    $todate = $object->attribute( 'modified' );

    if ( $todate < $deleteAfterThisDate )
    {
        echo ("removing object: " .   $object->attribute( 'id' ) . " " .$object->attribute( 'name'). "\n");
        $node->remove();
        $object->purge();
    }
}

Ɓukasz Serwatka

Wednesday 26 April 2006 11:30:23 pm

Hi,

Look on this topic:
http://ez.no/community/forum/general/help_with_delete_script/re_help_with_delete_script__2

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.