migrated delete expired revisions hourly script to a workflow activity

This commit is contained in:
JT Smith 2006-03-01 22:57:13 +00:00
parent 741de69841
commit ba3668643e
4 changed files with 117 additions and 40 deletions

View file

@ -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.revisionDate<? order by assetData.revisionDate asc", [time() - $self->get("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;

View file

@ -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,