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.

eZ debug

Timing: Jan 18 2025 22:39:23
Script start
Timing: Jan 18 2025 22:39:23
Module start 'layout'
Timing: Jan 18 2025 22:39:23
Module start 'content'
Timing: Jan 18 2025 22:39:24
Module end 'content'
Timing: Jan 18 2025 22:39:24
Script end

Main resources:

Total runtime0.6496 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 588.0391152.6406
Module start 'layout' 0.00690.0020 740.679739.4766
Module start 'content' 0.00890.6394 780.1563527.6641
Module end 'content' 0.64830.0012 1,307.82038.1250
Script end 0.6496  1,315.9453 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4917160.0002
Check MTime0.00130.2055160.0001
Mysql Total
Database connection0.00090.143110.0009
Mysqli_queries0.609593.8316540.0113
Looping result0.00050.0706520.0000
Template Total0.621895.720.3109
Template load0.00220.346220.0011
Template processing0.619595.369220.3098
Template load and register function0.00020.033910.0002
states
state_id_array0.00080.129310.0008
state_identifier_array0.00120.184120.0006
Override
Cache load0.00190.2859110.0002
Sytem overhead
Fetch class attribute can translate value0.00050.084120.0003
Fetch class attribute name0.00090.139330.0003
XML
Image XML parsing0.00070.103620.0003
class_abstraction
Instantiating content class attribute0.00000.000930.0000
General
dbfile0.00070.1099180.0000
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 10
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs