This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » General » Empty a very big trash
expandshrink

Empty a very big trash

Empty a very big trash

Thursday 03 February 2011 5:52:22 pm - 7 replies

Hi,

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

Thx

Thursday 03 February 2011 6:15:36 pm

Oh yea happy.gif Emoticon

#!/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();
?>

Modified on Thursday 03 February 2011 6:17:27 pm by Ivo Lukač

Thursday 03 February 2011 9:38:23 pm

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

Cheers

Saturday 05 February 2011 5:03:02 pm

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.

Friday 01 June 2012 1:04:47 pm

Thanks Ivo,

Your script saved my life!

Best regards,

Jean-Luc.

Friday 01 June 2012 1:17:48 pm

Actually eZ Publish has by default a script to purge trash located on:

./bin/php/trashpurge.php

Modified on Friday 01 June 2012 1:18:35 pm by Israel Martín

Friday 01 June 2012 1:34:03 pm

Quote from Israel Martín :

Actually eZ Publish has by default a script to purge trash located on:

./bin/php/trashpurge.php

Yea, that came recently (maybe in 4.5) with only info as one line in change log, so nobody noticed happy.gif Emoticon

Monday 19 November 2012 4:21:53 pm

Hi,

trashpurge.php is nice, but it might be better with parameters like "delete all objects, 30 days and older in trash" so that it is really useful?

What do you think about?

Greetings, ekke

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from