added archive old posts activity
This commit is contained in:
parent
841c430ab4
commit
3f55240237
4 changed files with 106 additions and 43 deletions
|
|
@ -135,6 +135,8 @@ sub addWorkflow {
|
|||
$activity = $workflow->addActivity("WebGUI::Workflow::Activity::TrashClipboard", "pbwfactivity0000000004");
|
||||
$activity->set("title", "Move clipboard items older than 30 days to trash");
|
||||
$activity->set("trashAfter", 60*60*24*30);
|
||||
$activity = $workflow->addActivity("WebGUI::Workflow::Activity::ArchiveOldPosts", "pbwfactivity0000000005");
|
||||
$activity->set("title", "Archive old CS posts");
|
||||
WebGUI::Workflow::Cron->create($session, {
|
||||
title=>'Weekly Maintenance Maintenance',
|
||||
enabled=>1,
|
||||
|
|
|
|||
92
lib/WebGUI/Workflow/Activity/ArchiveOldPosts.pm
Normal file
92
lib/WebGUI/Workflow/Activity/ArchiveOldPosts.pm
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package WebGUI::Workflow::Activity::ArchiveOldPosts;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Workflow::Activity';
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Workflow::Activity::ArchiveOldPosts
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Uses the settings in the collaboration systems to determine whether the posts in those collaboration systems should be archived.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
See WebGUI::Workflow::Activity for details on how to use any activity.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( session, definition )
|
||||
|
||||
See WebGUI::Workflow::Activity::defintion() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session, "Workflow_Activity_ArchiveOldPosts");
|
||||
push(@{$definition}, {
|
||||
name=>$i18n->get("topicName"),
|
||||
properties=> {}
|
||||
});
|
||||
return $class->SUPER::definition($session,$definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 execute ( )
|
||||
|
||||
See WebGUI::Workflow::Activity::execute() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub execute {
|
||||
my $self = shift;
|
||||
my $epoch = $self->session->datetime->time();
|
||||
my $a = $self->session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Collaboration'");
|
||||
while (my ($assetId) = $a->array) {
|
||||
my $cs = WebGUI::Asset::Wobject::Collaboration->new($assetId);
|
||||
my $archiveDate = $epoch - $cs->get("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.dateUpdated<? and assetData.status='approved' and asset.state='published'
|
||||
and asset.lineage like ?";
|
||||
my $b = $self->session->db->read($sql,[$archiveDate, $cs->get("lineage").'%']);
|
||||
while (my ($id, $version) = $b->array) {
|
||||
my $post = WebGUI::Asset::Post->new($id,undef,$version);
|
||||
$post->setStatusArchived if (defined $post && $post->get("dateUpdated") < $archiveDate);
|
||||
}
|
||||
$b->finish;
|
||||
}
|
||||
$a->finish;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
12
lib/WebGUI/i18n/English/Workflow_Activity_ArchiveOldPosts.pm
Normal file
12
lib/WebGUI/i18n/English/Workflow_Activity_ArchiveOldPosts.pm
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package WebGUI::i18n::English::Workflow_Activity_ArchiveOldPosts;
|
||||
|
||||
our $I18N = {
|
||||
'topicName' => {
|
||||
message => q|Archive Old Posts|,
|
||||
context => q|The name of this workflow activity.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package Hourly::ArchiveOldPosts;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
||||
use strict;
|
||||
use WebGUI::Asset::Post;
|
||||
use WebGUI::Asset::Wobject::Collaboration;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
#-----------------------------------------
|
||||
sub process {
|
||||
my $epoch = WebGUI::DateTime::time();
|
||||
my $a = WebGUI::SQL->read("select assetId from asset where className='WebGUI::Asset::Wobject::Collaboration'");
|
||||
while (my ($assetId) = $a->array) {
|
||||
my $cs = WebGUI::Asset::Wobject::Collaboration->new($assetId);
|
||||
my $archiveDate = $epoch - $cs->get("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.dateUpdated<$archiveDate and assetData.status='approved' and asset.state='published'
|
||||
and asset.lineage like ".quote($cs->get("lineage").'%');
|
||||
my $b = WebGUI::SQL->read($sql);
|
||||
while (my ($id, $version) = $b->array) {
|
||||
my $post = WebGUI::Asset::Post->new($id,undef,$version);
|
||||
$post->setStatusArchived if (defined $post && $post->get("dateUpdated") < $archiveDate);
|
||||
}
|
||||
$b->finish;
|
||||
}
|
||||
$a->finish;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue