Forums / General / Empty a very big trash

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