Update ArchiveOldThreads Workflow activity.

This commit is contained in:
Colin Kuskie 2010-01-28 10:59:14 -08:00
parent 50c3e9c6ab
commit ad46ecfde2

View file

@ -18,6 +18,8 @@ package WebGUI::Workflow::Activity::ArchiveOldThreads;
use strict; use strict;
use base 'WebGUI::Workflow::Activity'; use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset; use WebGUI::Asset;
use WebGUI::Asset::Wobject::Collaboration;
use WebGUI::Exception;
=head1 NAME =head1 NAME
@ -69,20 +71,29 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute { sub execute {
my $self = shift; my $self = shift;
my $epoch = $self->session->datetime->time(); my $session = $self->session;
my $a = $self->session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Collaboration'"); my $epoch = $session->datetime->time();
while (my ($assetId) = $a->array) { my $getCs = WebGUI::Asset::Wobject::Collaboration->getIsa($session);
my $cs = WebGUI::Asset->new($self->session, $assetId, "WebGUI::Asset::Wobject::Collaboration"); CS: while (1) {
next unless defined $cs; my $cs = eval { $getCs->(); };
next unless $cs->get("archiveEnabled"); if (Exception::Class->caught()) {
my $archiveDate = $epoch - $cs->get("archiveAfter"); $session->log->error("Unable to instance Collaboration System: $@");
next CS;
}
last CS unless $cs;
next CS unless $cs->archiveEnabled;
my $archiveDate = $epoch - $cs->archiveAfter;
my $sql = "select asset.assetId, assetData.revisionDate from Post left join asset on asset.assetId=Post.assetId my $sql = "select asset.assetId, assetData.revisionDate from Post left join asset on asset.assetId=Post.assetId
left join assetData on Post.assetId=assetData.assetId and Post.revisionDate=assetData.revisionDate left join assetData on Post.assetId=assetData.assetId and Post.revisionDate=assetData.revisionDate
where Post.revisionDate<? and assetData.status='approved' and asset.state='published' where Post.revisionDate<? and assetData.status='approved' and asset.state='published'
and Post.threadId=Post.assetId and asset.lineage like ?"; and Post.threadId=Post.assetId and asset.lineage like ?";
my $b = $self->session->db->read($sql,[$archiveDate, $cs->get("lineage").'%']); my $b = $session->db->read($sql,[$archiveDate, $cs->lineage.'%']);
while (my ($id, $version) = $b->array) { THREAD: while (my ($id, $version) = $b->array) {
my $thread = WebGUI::Asset->new($self->session, $id, "WebGUI::Asset::Post::Thread", $version); my $thread = eval { WebGUI::Asset->newById($session, $id, $version); };
if (WebGUI::Exception->caught()) {
$session->log->error("Unable to instanciate Thread: $@");
next THREAD;
}
my $archiveIt = 1; my $archiveIt = 1;
foreach my $post (@{$thread->getPosts}) { foreach my $post (@{$thread->getPosts}) {
$archiveIt = 0 if (defined $post && $post->get("revisionDate") > $archiveDate); $archiveIt = 0 if (defined $post && $post->get("revisionDate") > $archiveDate);
@ -91,7 +102,6 @@ sub execute {
} }
$b->finish; $b->finish;
} }
$a->finish;
return $self->COMPLETE; return $self->COMPLETE;
} }