From 8b25005515aa32fb16447c50628dd5b44988ee60 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 26 Oct 2010 11:43:22 -0700 Subject: [PATCH] Allow Workflow activities to do cleanup when they're deleted. Fixes bug #11924. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Workflow/Activity.pm | 16 ++++++++++++++++ .../Activity/RequestApprovalForVersionTag.pm | 17 +++++++++++++++++ lib/WebGUI/Workflow/Instance.pm | 19 +++++++++++++++---- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a58b008bf..52853bd5e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -7,6 +7,7 @@ - fixed #11925: Some problems in Thingy export (metaData values in CSV export) - fixed #11925: Some problems in Thingy export (export times out on Things with many rows) - refixed #11902: forums bug (works without mobile style being set) + - fixed #11924: Deleting version tags leaves pending inbox messages in a permanent state 7.10.3 - fixed #11903: Unnecessary debug in Thingy diff --git a/lib/WebGUI/Workflow/Activity.pm b/lib/WebGUI/Workflow/Activity.pm index 5e3ecc862..b872d7b3c 100644 --- a/lib/WebGUI/Workflow/Activity.pm +++ b/lib/WebGUI/Workflow/Activity.pm @@ -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. diff --git a/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm b/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm index 7186b578c..dee69eba0 100644 --- a/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm +++ b/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm @@ -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. diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 83a2c0842..2e33e85fd 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -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().