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
|
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
|