Allow Workflow activities to do cleanup when they're deleted. Fixes bug #11924.

This commit is contained in:
Colin Kuskie 2010-10-26 11:43:22 -07:00
parent 0d46331745
commit 8b25005515
4 changed files with 49 additions and 4 deletions

View file

@ -76,6 +76,22 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 cleanup ( )
Override this activity to add a cleanup routine to be run if an instance
is deleted with this activity currently in a waiting state. This is a stub
and will do nothing unless overridden.
=cut
sub cleanup {
my $self = shift;
my $instance = shift;
return 1;
}
#-------------------------------------------------------------------
=head2 create ( session, workflowId [, id, classname ] )
Creates a new instance of this activity in a workflow.

View file

@ -44,6 +44,23 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 cleanup ( )
Override this activity to add a cleanup routine to be run if an instance
is deleted with this activity currently in a waiting state. This is a stub
and will do nothing unless overridden.
=cut
sub cleanup {
my $self = shift;
my $instance = shift;
$self->setMessageCompleted($instance);
return 1;
}
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::definition() for details.

View file

@ -101,11 +101,22 @@ A boolean, that if true will not notify Spectre of the delete.
=cut
sub delete {
my $self = shift;
my $self = shift;
my $session = $self->session;
my $skipNotify = shift;
$self->session->db->write("delete from WorkflowInstanceScratch where instanceId=?",[$self->getId]);
$self->session->db->deleteRow("WorkflowInstance","instanceId",$self->getId);
WebGUI::Workflow::Spectre->new($self->session)->notify("workflow/deleteInstance",$self->getId) unless ($skipNotify);
if ( $self->hasNextActivity ) {
#We are deleting in the middle of a workflow - Get the current activity and call the cleanup routine
my $activity = $self->getNextActivity;
eval { $activity->cleanup($self) };
if ($@) {
$session->errorHandler->error("Caught exception executing cleanup routine which was not run on workflow activity ".$activity->getId." for instance ".$self->getId.". The following error was reported: ".$@);
}
}
$session->db->write("delete from WorkflowInstanceScratch where instanceId=?",[$self->getId]);
$session->db->deleteRow("WorkflowInstance","instanceId",$self->getId);
WebGUI::Workflow::Spectre->new($session)->notify("workflow/deleteInstance",$self->getId) unless ($skipNotify);
# We will need to remember that we were deleted if we get realtime-run
# during start().