Update ArchiveOldThreads Workflow activity.
This commit is contained in:
parent
50c3e9c6ab
commit
ad46ecfde2
1 changed files with 43 additions and 33 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -47,15 +49,15 @@ See WebGUI::Workflow::Activity::definition() for details.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub definition {
|
sub definition {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $definition = shift;
|
my $definition = shift;
|
||||||
my $i18n = WebGUI::International->new($session, "Workflow_Activity_ArchiveOldThreads");
|
my $i18n = WebGUI::International->new($session, "Workflow_Activity_ArchiveOldThreads");
|
||||||
push(@{$definition}, {
|
push(@{$definition}, {
|
||||||
name=>$i18n->get("activityName"),
|
name=>$i18n->get("activityName"),
|
||||||
properties=> {}
|
properties=> {}
|
||||||
});
|
});
|
||||||
return $class->SUPER::definition($session,$definition);
|
return $class->SUPER::definition($session,$definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,31 +70,39 @@ See WebGUI::Workflow::Activity::execute() for details.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
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: $@");
|
||||||
my $sql = "select asset.assetId, assetData.revisionDate from Post left join asset on asset.assetId=Post.assetId
|
next CS;
|
||||||
left join assetData on Post.assetId=assetData.assetId and Post.revisionDate=assetData.revisionDate
|
|
||||||
where Post.revisionDate<? and assetData.status='approved' and asset.state='published'
|
|
||||||
and Post.threadId=Post.assetId and asset.lineage like ?";
|
|
||||||
my $b = $self->session->db->read($sql,[$archiveDate, $cs->get("lineage").'%']);
|
|
||||||
while (my ($id, $version) = $b->array) {
|
|
||||||
my $thread = WebGUI::Asset->new($self->session, $id, "WebGUI::Asset::Post::Thread", $version);
|
|
||||||
my $archiveIt = 1;
|
|
||||||
foreach my $post (@{$thread->getPosts}) {
|
|
||||||
$archiveIt = 0 if (defined $post && $post->get("revisionDate") > $archiveDate);
|
|
||||||
}
|
|
||||||
$thread->archive if ($archiveIt);
|
|
||||||
}
|
|
||||||
$b->finish;
|
|
||||||
}
|
}
|
||||||
$a->finish;
|
last CS unless $cs;
|
||||||
return $self->COMPLETE;
|
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
|
||||||
|
left join assetData on Post.assetId=assetData.assetId and Post.revisionDate=assetData.revisionDate
|
||||||
|
where Post.revisionDate<? and assetData.status='approved' and asset.state='published'
|
||||||
|
and Post.threadId=Post.assetId and asset.lineage like ?";
|
||||||
|
my $b = $session->db->read($sql,[$archiveDate, $cs->lineage.'%']);
|
||||||
|
THREAD: while (my ($id, $version) = $b->array) {
|
||||||
|
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;
|
||||||
|
foreach my $post (@{$thread->getPosts}) {
|
||||||
|
$archiveIt = 0 if (defined $post && $post->get("revisionDate") > $archiveDate);
|
||||||
|
}
|
||||||
|
$thread->archive if ($archiveIt);
|
||||||
|
}
|
||||||
|
$b->finish;
|
||||||
|
}
|
||||||
|
return $self->COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue