Snippets for eZ publish 3: RSS Delete Script - Allows you to limit the amount of RSS data in the system

This is compatible with eZ Publish 3.


This script was created for older versions of eZ Publish.

Users of eZ Publish 4.0+ should use BC Cleanup RSS instead.


The script runcronjobs.php goes out to all the active incoming RSS feeds in the system to collect content.

The following script ( rssdelete.php) can be added to the runcronjobs list by updating cronjob.ini, and placing the script in cronjobs, set to run immediately after rssimport.php.

It can be controlled through site.ini by setting [RSSSettings] MaxRSSObjects to the maximum number of RSS Objects you want in the system. If you forget to set the value, it will delete all RSS content immediately after import.


This retrieves all the RSS nodes sorted in descending order of publication. Thus, the most recent nodes will be returned first. An offset is used to skip the ini setting - so if there are less than that number of elements, no deletion will occur. You can add other filtering. This also disregards the location of the content, so as feeds are created and removed, the code will still run fine.


You can run it on the command line for testing, because runcronjobs can take a while to run.

Thanks to those who posted the code this is based on

//init shell script
include_once( 'kernel/classes/ezcontentobject.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobjecttreenodeoperations.php' );
include_once( "lib/ezutils/classes/ezextension.php" );
include_once( "lib/ezutils/classes/ezmodule.php" );
include_once( 'lib/ezutils/classes/ezcli.php' );
define ('SUBTREE_LIMIT',50);
if (!isset($script))
        include_once( 'kernel/classes/ezscript.php' );
        $script =& eZScript::instance( array( 'debug-message' => true,
                                      'use-session' => true,
                                      'use-modules' => true,
                                      'use-extensions' => true ) );
if (!isset($cli))
        $cli =& eZCLI::instance();
        $cli->setUseStyles( true ); // enable colors
include_once( "kernel/classes/ezdatatype.php" );
include_once( "kernel/classes/datatypes/ezuser/ezusersetting.php" );
include_once( "lib/ezutils/classes/ezmail.php" );
include_once ('kernel/classes/datatypes/ezuser/ezuser.php');
$user = eZUser::fetchByName('admin'); //*** ez administror
$userID = $user->attribute( 'contentobject_id' );
eZUser::setCurrentlyLoggedInUser( $user, $userID );
$cli->output('Checking for RSS objects',true);
include_once( 'lib/ezutils/classes/ezini.php' );
$ini =& eZINI::instance();
$max_RSS_objects = (int)$ini->variable( "RSSSettings","MaxRSSObjects" );
$cli->output('Current limit is '.$max_RSS_objects.' RSS objects per feed',true);
//fetch this class
include_once( 'kernel/classes/ezrssimport.php' );
$rssImportArray = eZRSSImport::fetchActiveList();
foreach ( array_keys( $rssImportArray ) as $rssImportKey )
        // Get RSSImport object
        $rssImport =& $rssImportArray[$rssImportKey];
        $parentNodeID = $rssImport->attribute( 'destination_node_id' ); // Get parent treenode object
if ($standalone)
function get_RSS_nodes ($today,$max_RSS_objects,$parentNodeID)
        global $cli;
        if ($max_RSS_objects === 0) return;
                        'ClassFilterType' => 'include',
                        'ClassFilterArray' => array(33),
                        'Limit' => SUBTREE_LIMIT,
                        'Depth' => 0,
                        'Offset' => $offset,
                        'SortBy' => array( 'published',false ),
//                        'AttributeFilter' => array('and',array('published','<=',$today)),
                        'status' => EZ_CONTENT_OBJECT_STATUS_PUBLISHED);
                $childNodes =& eZContentObjectTreeNode::subTree($params,$parentNodeID);
                if (count($childNodes) === 0)
                        foreach( $childNodes as $child )
                                $deleteIDArray[] = $id = $child->attribute( 'main_node_id' );
                                $cli->output('Deleting: '.$child->attribute('name').' ['.$id.']',true);
                        eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
                        unset ($childNodes);
        while (!$done);

External referencce