From 90cb569bb5ab622269efff79b59513d914172e7d Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 15 Sep 2006 06:08:30 +0000 Subject: [PATCH] - fix: deleting workflows did not delete related instances and crons - Added a "run" link to the scheduler and the running workflows listings to aid in debugging workflow errors. - fix: profile fields not validated by WebGUI::User --- docs/changelog/7.x.x.txt | 5 ++++ lib/WebGUI/AdSpace/Ad.pm | 3 +- lib/WebGUI/Operation/Cron.pm | 6 ++-- lib/WebGUI/Operation/Workflow.pm | 10 ++++--- lib/WebGUI/Session/Url.pm | 2 +- lib/WebGUI/User.pm | 1 + lib/WebGUI/Workflow.pm | 31 +++++++++++++++++++ lib/WebGUI/i18n/English/Workflow.pm | 6 ++++ t/AdSpace/Ad.t | 46 +++++++++++++++++++++++++++++ 9 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 t/AdSpace/Ad.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 92e54e734..bf424b403 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -3,6 +3,11 @@ Approval for Version Tag workflow activity. - Updated the hoverhelp to denote that you can use ranges in the WebGUI scheduler. + - fix: deleting workflows did not delete related instances and crons + - Added a "run" link to the scheduler and the running workflows listings to + aid in debugging workflow errors. + - fix: profile fields not validated by WebGUI::User + 7.0.7 - rfe: Image Management (funded by Formation Design Systems) diff --git a/lib/WebGUI/AdSpace/Ad.pm b/lib/WebGUI/AdSpace/Ad.pm index 51f080bec..ab5f70c50 100644 --- a/lib/WebGUI/AdSpace/Ad.pm +++ b/lib/WebGUI/AdSpace/Ad.pm @@ -52,6 +52,7 @@ The unique id of an ad space to attach this ad to. =head3 properties The properties used to create this object. See the set() method for details. +A hash must be passed into create and a "type" key of either "text", "rich" or "image" is mandatory. =cut @@ -209,7 +210,7 @@ The hex color to be used to display the border on a text based ad. =head4 textColor -THe hex color to be used to display the text on a test based ad. +The hex color to be used to display the text on a test based ad. =head4 backgroundColor diff --git a/lib/WebGUI/Operation/Cron.pm b/lib/WebGUI/Operation/Cron.pm index 05e322fdd..c9f03d6a8 100644 --- a/lib/WebGUI/Operation/Cron.pm +++ b/lib/WebGUI/Operation/Cron.pm @@ -233,7 +233,9 @@ sub www_manageCron { .$session->icon->edit("op=editCronJob;id=".$id) .''.$title.''.$schedule.'' .($enabled ? $i18n->get("enabled") : $i18n->get("disabled")) - ."\n"; + .""; + $output .= ''.$i18n->get("run","Workflow").''; + $output .= "\n"; } $output .= ''; my $ac = WebGUI::AdminConsole->new($session,"cron"); @@ -254,7 +256,7 @@ sub www_runCronJob { my $session = shift; $session->http->setMimeType("text/plain"); $session->http->setCacheControl("none"); - unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets"))) { + unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets")) || $session->user->isInGroup("3")) { $session->errorHandler->security("make a Spectre cron job runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")})."."); return "error"; } diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index bbbb9b961..427726747 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -370,7 +370,7 @@ sub www_runWorkflow { my $session = shift; $session->http->setMimeType("text/plain"); $session->http->setCacheControl("none"); - unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets"))) { + unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets")) || $session->user->isInGroup("3")) { $session->errorHandler->security("make a Spectre workflow runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")})."."); return "error"; } @@ -407,9 +407,10 @@ sub www_showRunningWorkflows { .disabled { color: #808000; } .done { color: #008000; } .undefined { color: #800000; } - '; - my $rs = $session->db->read("select Workflow.title, WorkflowInstance.lastStatus, WorkflowInstance.runningSince, WorkflowInstance.lastUpdate from WorkflowInstance left join Workflow on WorkflowInstance.workflowId=Workflow.workflowId order by WorkflowInstance.runningSince desc"); - while (my ($title, $status, $runningSince, $lastUpdate) = $rs->array) { +
'; + my $isAdmin = $session->user->isInGroup("3"); + my $rs = $session->db->read("select Workflow.title, WorkflowInstance.lastStatus, WorkflowInstance.runningSince, WorkflowInstance.lastUpdate, WorkflowInstance.instanceId from WorkflowInstance left join Workflow on WorkflowInstance.workflowId=Workflow.workflowId order by WorkflowInstance.runningSince desc"); + while (my ($title, $status, $runningSince, $lastUpdate, $id) = $rs->array) { my $class = $status || "complete"; $output .= '' .'' @@ -419,6 +420,7 @@ sub www_showRunningWorkflows { .$status.' / '.$session->datetime->epochToHuman($lastUpdate) .''; } + $output .= '' if ($isAdmin); $output .= "\n"; } $output .= '
'.$title.''.$i18n->get("run").'
'; diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index 7df65ab5d..fd10108bf 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -44,7 +44,7 @@ This package provides URL writing functionality. It is important that all WebGUI $string = $url->getSiteURL; $string = $url->makeCompliant($string); $string = $url->makeAbsolute($string); - $string = $url->page($string, $pairs); + $string = $url->page($pairs); $string = $url->unescape($string); $string = $url->urlize($string); diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 4660f74fe..3ed07e1d3 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -439,6 +439,7 @@ sub profileField { $self = shift; $fieldName = shift; $value = shift; + die "No such profile field: $fieldName" unless $self->session->db->quickArray("SELECT COUNT(*) FROM userProfileField WHERE fieldName = ?", [$fieldName]); if (defined $value) { $self->uncache; $self->{_profile}{$fieldName} = $value; diff --git a/lib/WebGUI/Workflow.pm b/lib/WebGUI/Workflow.pm index afd32b894..1b837cefd 100644 --- a/lib/WebGUI/Workflow.pm +++ b/lib/WebGUI/Workflow.pm @@ -228,6 +228,37 @@ sub getActivities { return \@activities; } +=head2 getInstances ( ) + +Returns an array reference of the instance objects currently existing for this workflow. + +=cut + +sub getInstances { + my $self = shift; + my @instances = (); + my $rs = $self->session->db->read("SELECT instanceId FROM WorkflowInstance WHERE workflowId = ?", [$self->getId]); + while (my ($instanceId) = $rs->array) { + push(@instances, WebGUI::Workflow::Instance->new($self->session, $instanceId)); + } + return \@instances; +} + +=head2 getCrons ( ) + +Returns an array reference of the cron objects that trigger this workflow. + +=cut + +sub getCrons { + my $self = shift; + my @crons = (); + my $rs = $self->session->db->read("SELECT taskId FROM WorkflowSchedule WHERE workflowId = ?", [$self->getId]); + while (my ($taskId) = $rs->array) { + push(@crons, WebGUI::Workflow::Cron->new($self->session, $taskId)); + } + return \@crons; +} #------------------------------------------------------------------- diff --git a/lib/WebGUI/i18n/English/Workflow.pm b/lib/WebGUI/i18n/English/Workflow.pm index e642a0467..4fda8d386 100644 --- a/lib/WebGUI/i18n/English/Workflow.pm +++ b/lib/WebGUI/i18n/English/Workflow.pm @@ -1,6 +1,12 @@ package WebGUI::i18n::English::Workflow; our $I18N = { + 'run' => { + message => q|Run|, + context => q|Execute a workflow.|, + lastUpdated => 0, + }, + 'show running workflows' => { message => q|Show running workflows.|, context => q|A label used to get to a display of running workflows.|, diff --git a/t/AdSpace/Ad.t b/t/AdSpace/Ad.t new file mode 100644 index 000000000..3b9db05eb --- /dev/null +++ b/t/AdSpace/Ad.t @@ -0,0 +1,46 @@ +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; +use WebGUI::Test; +use WebGUI::Session; +use WebGUI::AdSpace; + +#use Test::More tests => 3; +use Test::More; + +my $numTests = 1; # increment this value for each test you create +++$numTests; ##For conditional testing on module load + +plan tests => $numTests; + +my $loaded = use_ok('WebGUI::AdSpace::Ad'); + +my $session = WebGUI::Test->session; +my $ad; +my $adSpace; + +SKIP: { + + skip "Unable to load WebGUI::AdSpace::Ad", $numTests-1 unless $loaded; + $adSpace = WebGUI::AdSpace->create($session, {name=>"Alfred"}); + $ad=WebGUI::AdSpace::Ad->create($session, $adSpace->getId, {"type", "text"}); + isa_ok($ad,"WebGUI::AdSpace::Ad","testing create with no properties"); +} +END { + if (defined $ad and ref $ad eq 'WebGUI::AdSpace::Ad') { + $ad->delete; + } + if (defined $adSpace and ref $adSpace eq 'WebGUI::AdSpace') { + $adSpace->delete; + } +}