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();
}
}
|