getting a baseline activity working for testing
This commit is contained in:
parent
662c43ca21
commit
806e47e51c
2 changed files with 201 additions and 2 deletions
|
|
@ -16,7 +16,7 @@ package WebGUI::Workflow::Activity;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
|
||||
use WebGUI::HTMLForm;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -90,6 +90,24 @@ sub DESTROY {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 execute ( object )
|
||||
|
||||
This method will be called during workflow operation. It needs to be overridden by the base classes.
|
||||
|
||||
=head2 object
|
||||
|
||||
A reference to some object that will be passed in to this activity for an action to be taken on it.
|
||||
|
||||
=cut
|
||||
|
||||
sub execute {
|
||||
my $self = shift;
|
||||
my $object = shift;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( name )
|
||||
|
|
@ -105,6 +123,20 @@ sub get {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditForm ( )
|
||||
|
||||
Returns a WebGUI::HTMLForm object that represents the parameters of this activity. This method must be extended by the subclasses.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $form = WebGUI::HTMLForm->new($self->session);
|
||||
return $form;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ( )
|
||||
|
||||
Returns the ID of this instance.
|
||||
|
|
@ -118,6 +150,23 @@ sub getId {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( session )
|
||||
|
||||
Returns the name of the activity. Must be overridden. This is a class method.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
my $session = shift;
|
||||
return "Unnamed";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session, activityId )
|
||||
|
||||
Constructor.
|
||||
|
|
@ -137,9 +186,9 @@ sub new {
|
|||
my $session = shift;
|
||||
my $activityId = shift;
|
||||
my $main = $session->db->getRow("WorkflowActivity","activityId", $activityId);
|
||||
return undef unless $main->{activityId};
|
||||
my $sub = $session->db->buildHashRef("select name,value from WorkflowActivityData where activityId=".$session->db->quote($activityId));
|
||||
my %data = (%{$main}, %{$sub});
|
||||
return undef unless $data->{activityId};
|
||||
bless {_session=>$session, _id=>$activityId, _data=>\%data}, $class;
|
||||
}
|
||||
|
||||
|
|
|
|||
150
lib/WebGUI/Workflow/Activity/CleanTempStorage.pm
Normal file
150
lib/WebGUI/Workflow/Activity/CleanTempStorage.pm
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
package WebGUI::Workflow::Activity::CleanTempStorage;
|
||||
|
||||
|
||||
=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 File::Path;
|
||||
use File::stat;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Workflow::Activity::CleanTempStorage
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This activity cleans out temp storage after it's been sitting there a while.
|
||||
|
||||
=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 checkFileAge ( pathToFile )
|
||||
|
||||
Returns a boolean indicating whether the file is old enough to deleted or not.
|
||||
|
||||
=head3 pathToFile
|
||||
|
||||
The fully qualified path to the filename.
|
||||
|
||||
=cut
|
||||
|
||||
sub checkFileAge {
|
||||
my $self = shift;
|
||||
my $path = shift;
|
||||
my ($filestat, $flag);
|
||||
$filestat = stat($path) or print "No $path: $!";
|
||||
if ((time()-$filestat->mtime) > $self->get("storageTimeout")) {
|
||||
$flag = 1;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
return $flag;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 recurseFileSystem ( path )
|
||||
|
||||
Recurses the filesystem deleting files older than the specified time.
|
||||
|
||||
=head3 path
|
||||
|
||||
The starting path.
|
||||
|
||||
=cut
|
||||
|
||||
sub recurseFileSystem {
|
||||
my $self = shift;
|
||||
my $path = shift;
|
||||
my (@filelist, $file);
|
||||
if (opendir(DIR,$path)) {
|
||||
@filelist = readdir(DIR);
|
||||
closedir(DIR);
|
||||
foreach $file (@filelist) {
|
||||
unless ($file eq "." || $file eq "..") {
|
||||
$self->recurseFileSystem($path."/".$file);
|
||||
if ($self->checkFileAge($path."/".$file)) {
|
||||
rmtree($path."/".$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 execute ( )
|
||||
|
||||
See WebGUI::Workflow::Activity::execute() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub execute {
|
||||
my $self = shift;
|
||||
$self->recurseFileSystem($self->session->config->get("uploadsPath")."/temp");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditForm ( )
|
||||
|
||||
See WebGUI::Workflow::Activity::getEditForm() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $form = $self->SUPER::getEditForm();
|
||||
$form->interval(
|
||||
-name=>"storageTimeout",
|
||||
-label=>"Storage Timeout",
|
||||
-defaultValue=>6*60*60,
|
||||
-value=>$self->get("storageTimeout")
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( session )
|
||||
|
||||
See WebGUI::Workflow::Activity::getName() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
my $session = shift;
|
||||
return "Clean Temp Storage";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue