Fix PurgeOldTrash, and force it to follow TTL checking.

This commit is contained in:
Colin Kuskie 2010-01-27 22:36:35 -08:00
parent 872dcfceab
commit 7bb09ae30d

View file

@ -18,6 +18,7 @@ package WebGUI::Workflow::Activity::PurgeOldTrash;
use strict; use strict;
use base 'WebGUI::Workflow::Activity'; use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset; use WebGUI::Asset;
use WebGUI::Exception;
=head1 NAME =head1 NAME
@ -75,13 +76,26 @@ See WebGUI::Workflow::Activity::execute() for details.
=cut =cut
sub execute { sub execute {
my $self = shift; my $self = shift;
my $sth = $self->session->db->read("select assetId,className from asset where state='trash' and stateChanged < ?", [time() - $self->get("purgeAfter")]); my $session = $self->session;
while (my ($id, $class) = $sth->array) { my $sth = $session->db->read("select assetId,className from asset where state='trash' and stateChanged < ?", [time() - $self->get("purgeAfter")]);
my $asset = WebGUI::Asset->new($self->session, $id,$class); my $start = time();
$asset->purge if (defined $asset); my $ttl = $self->getTTL;
ASSET: while (my ($id, $class) = $sth->array) {
my $asset = eval { WebGUI::Asset->newById($session, $id); };
if (Exception::Class->caught()) {
$session->log->warn("Unable to instanciate assetId $id: $@");
next ASSET;
} }
return $self->COMPLETE; $asset->purge;
if (time() - $start > $ttl) {
$session->log->info("Ran out of time processing");
$sth->finish;
return $self->WAITING(1);
}
}
$sth->finish;
return $self->COMPLETE;
} }