diff --git a/docs/upgrades/upgrade_6.8.7-6.99.0.pl b/docs/upgrades/upgrade_6.8.7-6.99.0.pl index a5e29cef1..8d4602e3e 100644 --- a/docs/upgrades/upgrade_6.8.7-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.7-6.99.0.pl @@ -128,7 +128,8 @@ sub addWorkflow { $session->config->set("workflowActivities", { None=>["WebGUI::Workflow::Activity::DecayKarma", "WebGUI::Workflow::Activity::TrashClipboard", "WebGUI::Workflow::Activity::CleanTempStorage", "WebGUI::Workflow::Activity::CleanFileCache", "WebGUI::Workflow::Activity::CleanLoginHistory", "WebGUI::Workflow::Activity::ArchiveOldThreads", - "WebGUI::Workflow::Activity::TrashExpiredEvents", "WebGUI::Workflow::Activity::CreateCronJob"], + "WebGUI::Workflow::Activity::TrashExpiredEvents", "WebGUI::Workflow::Activity::CreateCronJob", + "WebGUI::Workflow::Activity::DeleteExpiredGroupings"], "WebGUI::User"=>["WebGUI::Workflow::Activity::CreateCronJob"], "WebGUI::VersionTag"=>["WebGUI::Workflow::Activity::CommitVersionTag", "WebGUI::Workflow::Activity::RollbackVersionTag", "WebGUI::Workflow::Activity::TrashVersionTag", "WebGUI::Workflow::Activity::CreateCronJob"] @@ -150,6 +151,8 @@ sub addWorkflow { $activity = $workflow->addActivity("WebGUI::Workflow::Activity::TrashExpiredEvents", "pbwfactivity0000000006"); $activity->set("title", "Trash old Events Calendar Events"); $activity->set("trashAfter", 60*60*24*30); + $activity = $workflow->addActivity("WebGUI::Workflow::Activity::DeleteExpiredGroupings", "pbwfactivity0000000007"); + $activity->set("title", "Delete groupings that have expired"); WebGUI::Workflow::Cron->create($session, { title=>'Daily Maintenance', enabled=>1, diff --git a/lib/WebGUI/Workflow/Activity/DeleteExpiredGroupings.pm b/lib/WebGUI/Workflow/Activity/DeleteExpiredGroupings.pm new file mode 100644 index 000000000..00d10176a --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/DeleteExpiredGroupings.pm @@ -0,0 +1,87 @@ +package WebGUI::Workflow::Activity::DeleteExpiredGroupings; + + +=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'; +use WebGUI::Cache::FileCache; + +=head1 NAME + +Package WebGUI::Workflow::Activity::DeleteExpiredGroupings; + +=head1 DESCRIPTION + +Deletes user groupings that are past their expire date. + +=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_DeleteExpiredGroupings"); + 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 $sth = $self->session->db->read("select groupId,deleteOffset,dbCacheTimeout from groups"); + while (my $data = $sth->hashRef) { + if ($data->{dbCacheTimeout} > 0) { + # there is no need to wait deleteOffset days for expired external group cache data + $self->session->db->write("delete from groupings where groupId=? and expireDate < ?", [$data->{groupId}, time()]); + } else { + $self->session->db->write("delete from groupings where groupId=? and expireDate < ?", [$data->{groupId}, time()-(86400*$data->{deleteOffset})]); + } + } +} + + + +1; + + diff --git a/lib/WebGUI/i18n/English/Workflow_Activity_DeleteExpiredGroupings.pm b/lib/WebGUI/i18n/English/Workflow_Activity_DeleteExpiredGroupings.pm new file mode 100644 index 000000000..35c20f8d0 --- /dev/null +++ b/lib/WebGUI/i18n/English/Workflow_Activity_DeleteExpiredGroupings.pm @@ -0,0 +1,12 @@ +package WebGUI::i18n::English::Workflow_Activity_DeleteExpiredGroupings; + +our $I18N = { + 'topicName' => { + message => q|Delete Expired Groupings|, + context => q|The name of this workflow activity.|, + lastUpdated => 0, + }, + +}; + +1; diff --git a/sbin/Hourly/DeleteExpiredGroupings.pm b/sbin/Hourly/DeleteExpiredGroupings.pm deleted file mode 100644 index ddc399ec8..000000000 --- a/sbin/Hourly/DeleteExpiredGroupings.pm +++ /dev/null @@ -1,37 +0,0 @@ -package Hourly::DeleteExpiredGroupings; - -#------------------------------------------------------------------- -# 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::DateTime; -use WebGUI::Session; -use WebGUI::SQL; - -#----------------------------------------- -sub process { - my @date = WebGUI::DateTime::localtime(); - if ($date[3] == 3) { # only occurs at 3am on the day in question. - my $sth = WebGUI::SQL->read("select groupId,deleteOffset,dbCacheTimeout from groups"); - while (my $data = $sth->hashRef) { - if ($data->{dbCacheTimeout} > 0) { - # there is no need to wait deleteOffset days for expired external group cache data - WebGUI::SQL->write("delete from groupings where groupId=".quote($data->{groupId})." and expireDate < ".WebGUI::DateTime::time()); - } else { - WebGUI::SQL->write("delete from groupings where groupId=".quote($data->{groupId})." and expireDate < " - .(WebGUI::DateTime::time()-(86400*$data->{deleteOffset}))); - } - } - $sth->finish; - } -} - -1; -