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 8d4602e3e..5f8de1e13 100644 --- a/docs/upgrades/upgrade_6.8.7-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.7-6.99.0.pl @@ -129,7 +129,7 @@ sub addWorkflow { 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::DeleteExpiredGroupings"], + "WebGUI::Workflow::Activity::DeleteExpiredGroupings", "WebGUI::Workflow::Activity::PurgeOldAssetRevisions"], "WebGUI::User"=>["WebGUI::Workflow::Activity::CreateCronJob"], "WebGUI::VersionTag"=>["WebGUI::Workflow::Activity::CommitVersionTag", "WebGUI::Workflow::Activity::RollbackVersionTag", "WebGUI::Workflow::Activity::TrashVersionTag", "WebGUI::Workflow::Activity::CreateCronJob"] @@ -176,6 +176,9 @@ 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::PurgeOldAssetRevisions", "pbwfactivity0000000008"); + $activity->set("title", "delete asset revisions older than a year from the database"); + $activity->set("purgeAfter", 60*60*24*365); WebGUI::Workflow::Cron->create($session, { title=>'Weekly Maintenance', enabled=>1, diff --git a/lib/WebGUI/Workflow/Activity/PurgeOldAssetRevisions.pm b/lib/WebGUI/Workflow/Activity/PurgeOldAssetRevisions.pm new file mode 100644 index 000000000..21dc8f620 --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/PurgeOldAssetRevisions.pm @@ -0,0 +1,95 @@ +package WebGUI::Workflow::Activity::PurgeOldAssetRevisions; + + +=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::Asset; + +=head1 NAME + +Package WebGUI::Workflow::Activity::PurgeOldAssetRevisions + +=head1 DESCRIPTION + +Removes old asset revisions from the database. + +=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, "Asset"); + push(@{$definition}, { + name=>$i18n->get("purge old asset revisions"), + properties=> { + purgeAfter=>{ + fieldType=>"interval", + defaultValue=>60*60*24*365, + label=>$i18n->get("purge revision after"), + hoverHelp=>$i18n->get("purge revision after help") + } + } + }); + 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 assetData.assetId,asset.className,assetData.revisionDate from asset left join assetData on asset.assetId=assetData.assetId where assetData.revisionDateget("purgeAfter")]); + while (my ($id, $class, $version) = $sth->array) { + my $asset = WebGUI::Asset->new($self->session, $id,$class,$version); + if ($asset->getRevisionCount("approved") > 1) { + $asset->purgeRevision; + } + } + $sth->finish; + return 1; +} + + + + +1; + + diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 3bea231d1..52ad61250 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1,6 +1,24 @@ package WebGUI::i18n::English::Asset; our $I18N = { + 'purge old asset revisions' => { + message => q|Purge Old Asset Revisions|, + lastUpdated => 0, + context => q|title of the purge old asset revisions workflow activity| + }, + + 'purge revision after' => { + message => q|Purge Old Revisions After|, + lastUpdated => 0, + context => q|the label used in the purge expired asset revisions workflow activity| + }, + + 'purge revision after help' => { + message => q|How long should old revisions of an asset be kept? Old asset revisions are those that are no longer viewable by users, but are kept in the versioning system for rollbacks.|, + lastUpdated => 0, + context => q|the hover help for the purge revision after field| + }, + 'purge revision prompt' => { message => q|Are you certain you wish to delete this revision of this asset? It CANNOT be restored if you delete it.|, lastUpdated => 0, diff --git a/sbin/Hourly/DeleteExpiredRevisions.pm b/sbin/Hourly/DeleteExpiredRevisions.pm deleted file mode 100644 index b24b31f44..000000000 --- a/sbin/Hourly/DeleteExpiredRevisions.pm +++ /dev/null @@ -1,39 +0,0 @@ -package Hourly::DeleteExpiredRevisions; - -#------------------------------------------------------------------- -# 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; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::DateTime; - -#----------------------------------------- -sub process { - if ($session{config}{DeleteExpiredRevisions_offset} ne "") { - my $hour = WebGUI::DateTime::epochToHuman(time(),"%H"); - my $dow = WebGUI::DateTime::epochToHuman(time(),"%W"); - return unless ($hour == 3 && $dow eq "Sun"); - my $expireDate = (time()-(86400*$session{config}{DeleteExpiredRevisions_offset})); - my $sth = WebGUI::SQL->read("select assetData.assetId,asset.className,assetData.revisionDate from asset left join assetData on asset.assetId=assetData.assetId where assetData.revisionDate<".$expireDate." order by assetData.revisionDate asc"); - while (my ($id, $class, $version) = $sth->array) { - my $asset = WebGUI::Asset->new($id,$class,$version); - if ($asset->getRevisionCount("approved") > 1) { - $asset->purgeRevision; - } - } - $sth->finish; - } -} - -1; -