diff --git a/docs/upgrades/upgrade_6.8.6-6.9.0.pl b/docs/upgrades/upgrade_6.8.6-6.9.0.pl index 52fb41a24..1561252e7 100644 --- a/docs/upgrades/upgrade_6.8.6-6.9.0.pl +++ b/docs/upgrades/upgrade_6.8.6-6.9.0.pl @@ -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, diff --git a/lib/WebGUI/Workflow/Activity/ArchiveOldPosts.pm b/lib/WebGUI/Workflow/Activity/ArchiveOldPosts.pm new file mode 100644 index 000000000..59608fd60 --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/ArchiveOldPosts.pm @@ -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.dateUpdatedsession->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; + + diff --git a/lib/WebGUI/i18n/English/Workflow_Activity_ArchiveOldPosts.pm b/lib/WebGUI/i18n/English/Workflow_Activity_ArchiveOldPosts.pm new file mode 100644 index 000000000..24e20e9b4 --- /dev/null +++ b/lib/WebGUI/i18n/English/Workflow_Activity_ArchiveOldPosts.pm @@ -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; diff --git a/sbin/Hourly/ArchiveOldPosts.pm b/sbin/Hourly/ArchiveOldPosts.pm deleted file mode 100644 index b32217f90..000000000 --- a/sbin/Hourly/ArchiveOldPosts.pm +++ /dev/null @@ -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; -