diff --git a/docs/upgrades/upgrade_6.8.5-6.9.0.pl b/docs/upgrades/upgrade_6.8.5-6.9.0.pl index 8d977aee4..ea68f897f 100644 --- a/docs/upgrades/upgrade_6.8.5-6.9.0.pl +++ b/docs/upgrades/upgrade_6.8.5-6.9.0.pl @@ -71,6 +71,7 @@ sub addWorkflow { title varchar(255) not null default 'Untitled', description text, enabled int not null default 0, + isSerial int not null default 0, type varchar(255) not null default 'none' )"); $session->db->write("create table WorkflowActivity ( diff --git a/lib/WebGUI/Workflow.pm b/lib/WebGUI/Workflow.pm index 5083d0fb9..76bec45ff 100644 --- a/lib/WebGUI/Workflow.pm +++ b/lib/WebGUI/Workflow.pm @@ -288,6 +288,10 @@ A boolean indicating whether this workflow may be executed right now. A string indicating the type of object this workflow will be operating on. Valid values are "none", "versiontag" and "user". +=head4 isSerial + +A boolean indicating whether this workflow can be run in parallel or serial. If it's serial, then only one instance of the workflow will be allowed to be created at a given time. So if you try to create a new instance of it, and one instance is already created, the create() method will return undef instead of a reference to the object. + =cut sub set { @@ -298,6 +302,11 @@ sub set { } elsif ($properties->{enabled} == 0) { $self->{_data}{enabled} = 0; } + if ($properties->{isSerial} == 1) { + $self->{_data}{isSerial} = 1; + } elsif ($properties->{isSerial} == 0) { + $self->{_data}{isSerial} = 0; + } $self->{_data}{title} = $properties->{title} || $self->{_data}{title} || "Untitled"; $self->{_data}{description} = (exists $properties->{description}) ? $properties->{description} : $self->{_data}{description}; $self->{_data}{type} = $properties->{type} || $self->{_data}{type} || "none"; diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 7c1027608..b35a5d93a 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -41,7 +41,7 @@ These methods are available from this class: =head2 create ( session, properties [, id ] ) -Creates a new workflow instance. +Creates a new workflow instance and returns a reference to the object. Will return undef if the workflow specified is serial and an instance of it already exists. =head3 session @@ -62,6 +62,9 @@ sub create { my $session = shift; my $properties = shift; my $id = shift; + my ($isSerial) = $session->db->quickArray("select isSerial from Workflow where workflowId=?",[$properties->{workflowId}]); + my ($count) = $session->db->quickArray("select count(*) from WorkflowInstance where workflowId=?",[$properties->{workflowId}]); + return undef if ($isSerial && $count); my $instanceId = $session->db->setRow("WorkflowInstance","instanceId",{instanceId=>"new", runningSince=>time()}, $id); my $self = $class->new($session, $instanceId); $self->set($properties);