Empty a very big trash

Author Message

Guillaume Kulakowski

Thursday 03 February 2011 8:52:22 am

Hi,

is there a script to empty a very large trash ? There is no option for that in flatten...

Thx

My blog : http://www.llaumgui.com (not in eZ Publish ;-))
eZC on RHEL : http://blog.famillecollet.com/pages/Config-en
eZC on Fedora : just "yum install php-channel-ezc"

Ivo Lukac

Thursday 03 February 2011 9:15:36 am

Oh yea :)

#!/usr/bin/env php
<?php
set_time_limit( 0 );
require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance( array( 'debug-message' => '', 'description' => ( "Empty trash" ), 'use-session' => false, 'use-modules' => true,  'use-extensions' => true ) );
$script->startup();
$options = $script->getOptions();
$script->initialize();
$script->setIterationData( '.', '~' );
$user = eZUser::fetch( 14 );
if ( !$user )    $script->shutdown( 1 );
eZUser::setCurrentlyLoggedInUser( $user, 14 );
eZExecution::registerShutdownHandler();
$db = eZDB::instance();
$def = eZContentObject::definition();
$conds = array( 'status' => eZContentObject::STATUS_ARCHIVED );
$count = eZPersistentObject::count( $def, $conds, 'id' );
$script->resetIteration( $count );
$offset=0;
$limit=1000;
$objectList = eZPersistentObject::fetchObjectList( $def,  null, $conds, null, array( 'offset' => $offset, 'length' => $limit ),true );
while (count($objectList)) {    
 $db->begin();
 foreach ( $objectList as $object ){        
  $object->purge();        
  $script->iterate( $cli, true );
 }    
 $db->commit();
 $offset=$offset + $limit;
 $objectList = eZPersistentObject::fetchObjectList( $def,  null, $conds, null, array( 'offset' => $offset, 'length' => $limit ),true );
}
$script->shutdown();
?>

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

Damien Pobel

Thursday 03 February 2011 12:38:23 pm

There's another script in the last comment of this issue : http://issues.ez.no/10827

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Marko Žmak

Saturday 05 February 2011 8:03:02 am

I think that the "right" way to fetch the trash nodes for iteration is this:

$objectList = eZContentObjectTrashNode::trashList( array( 'Limit' => $limit, 'Offset' => $offset ) ) ;

Besides being the right way of doing it I believe there's also a slight performance difference. Fetching trash nodes with eZContentObjectTrashNode::trashList() should be faster.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

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 02:18:20
Script start
Timing: Jan 18 2025 02:18:20
Module start 'layout'
Timing: Jan 18 2025 02:18:20
Module start 'content'
Timing: Jan 18 2025 02:18:21
Module end 'content'
Timing: Jan 18 2025 02:18:21
Script end

Main resources:

Total runtime1.3865 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 587.8047152.6094
Module start 'layout' 0.00550.0032 740.414139.4219
Module start 'content' 0.00871.3762 779.8359652.0234
Module end 'content' 1.38490.0015 1,431.859416.1875
Script end 1.3864  1,448.0469 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2272160.0002
Check MTime0.00130.0920160.0001
Mysql Total
Database connection0.00100.072010.0010
Mysqli_queries0.634645.7740650.0098
Looping result0.00070.0470630.0000
Template Total0.659347.620.3297
Template load0.00200.146220.0010
Template processing0.657347.405920.3286
Template load and register function0.00010.007310.0001
states
state_id_array0.00070.053410.0007
state_identifier_array0.00110.077420.0005
Override
Cache load0.00170.1199210.0001
Sytem overhead
Fetch class attribute can translate value0.00060.040640.0001
Fetch class attribute name0.00110.076680.0001
XML
Image XML parsing0.00190.140340.0005
class_abstraction
Instantiating content class attribute0.00000.000980.0000
General
dbfile0.00110.0807380.0000
String conversion0.00000.000440.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs