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 ea68f897f..f6a51f144 100644 --- a/docs/upgrades/upgrade_6.8.5-6.9.0.pl +++ b/docs/upgrades/upgrade_6.8.5-6.9.0.pl @@ -42,6 +42,7 @@ sub addWorkflow { $session->config->set("spectreCryptoKey","123qwe"); $session->db->write("create table WorkflowSchedule ( taskId varchar(22) binary not null primary key, + title varchar(255) not null default 'Untitled', enabled int not null default 0, runOnce int not null default 0, minuteOfHour varchar(25) not null default '0', @@ -98,6 +99,7 @@ sub addWorkflow { $activity->set("title","Delete files older than 24 hours"); $activity->set("storageTimeout",60*60*24); my $cron = WebGUI::Workflow::Cron->create($session, { + title=>'Delete temp files', enabled=>1, runOnce=>0, minuteOfHour=>"30", diff --git a/lib/WebGUI/AdminConsole.pm b/lib/WebGUI/AdminConsole.pm index 36c675002..018531b5d 100644 --- a/lib/WebGUI/AdminConsole.pm +++ b/lib/WebGUI/AdminConsole.pm @@ -161,6 +161,15 @@ sub getAdminFunction { func=>"manageVersions", group=>"3" }, + "cron"=>{ + title=>{ + id=>"topicName", + namespace=>"Workflow_Cron" + }, + icon=>"cron.gif", + op=>"manageCron", + group=>"3" + }, "users"=>{ title=>{ id=>"149", diff --git a/lib/WebGUI/Form/Captcha.pm b/lib/WebGUI/Form/Captcha.pm index 9e8292523..a6b8444a6 100644 --- a/lib/WebGUI/Form/Captcha.pm +++ b/lib/WebGUI/Form/Captcha.pm @@ -60,7 +60,7 @@ sub definition { my $i18n = WebGUI::International->new($session,"Form_Captcha"); push(@{$definition}, { formName=>{ - defaultValue=>$i18n->get("formName") + defaultValue=>$i18n->get("topicName") }, profileEnabled=>{ defaultValue=>1 diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index 074255061..4a01450e6 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -77,6 +77,10 @@ Returns a hash reference containing operation and package names. sub getOperations { return { + 'manageCron' => 'WebGUI::Operation::Cron', + 'editCronJob' => 'WebGUI::Operation::Cron', + 'editCronJobSave' => 'WebGUI::Operation::Cron', + 'deleteCronJob' => 'WebGUI::Operation::Cron', 'spectre' => 'WebGUI::Operation::Spectre', 'adminConsole' => 'WebGUI::Operation::Admin', 'switchOffAdmin' => 'WebGUI::Operation::Admin', diff --git a/lib/WebGUI/Operation/Cron.pm b/lib/WebGUI/Operation/Cron.pm new file mode 100644 index 000000000..11d3a6d5e --- /dev/null +++ b/lib/WebGUI/Operation/Cron.pm @@ -0,0 +1,188 @@ +package WebGUI::Operation::Cron; + +#------------------------------------------------------------------- +# 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 strict; +use Tie::IxHash; +use WebGUI::AdminConsole; +use WebGUI::HTMLForm; +use WebGUI::International; +use WebGUI::Workflow::Cron; + +=head1 NAME + +Package WebGUI::Operations::Cron + +=head1 DESCRIPTION + +Operation handler for managing scheduler activities. + +=cut + +#------------------------------------------------------------------- + +=head2 www_deleteCronJob ( ) + +Deletes a cron job. + +=cut + +sub www_deleteCronJob { + my $session = shift; + return $session->privilege->adminOnly() unless ($session->user->isInGroup(3)); + my $cron = WebGUI::Workflow::Cron->new($session, $session->form->get("id")); + $cron->delete if defined $cron; + return www_manageCron($session); +} + +#------------------------------------------------------------------- + +=head2 www_editCronJob ( ) + +Displays an edit form for a cron job. + +=cut + +sub www_editCronJob { + my $session = shift; + return $session->privilege->adminOnly() unless ($session->user->isInGroup(3)); + my $i18n = WebGUI::International->new($session, "Workflow_Cron"); + my $cron = WebGUI::Workflow::Cron->new($session, $session->form->get("id")); + my $f = WebGUI::HTMLForm->new($session); + $f->hidden( + name=>"op", + value=>"editCronJobSave" + ); + $f->hidden( + name=>"id", + value=>$session->form->get("id"), + defaultValue=>"new", + ); + $f->readOnly( + label=>$i18n->get("id"), + value=>$session->form->get("id"), + defaultValue=>"new" + ); + my $value = $cron->get("title") if defined $cron; + $f->text( + name=>"title", + value=>$value, + label=>$i18n->get("title"), + hoverHelp=>$i18n->get("title help") + ); + my $value = $cron->get("enabled") if defined $cron; + $f->yesNo( + name=>"enabled", + value=>$value, + defaultValue=>0, + label=>$i18n->get("enabled"), + hoverHelp=>$i18n->get("enabled help") + ); + my $value = $cron->get("runOnce") if defined $cron; + $f->yesNo( + name=>"runOnce", + value=>$value, + defaultValue=>0, + label=>$i18n->get("run once"), + hoverHelp=>$i18n->get("ron once help") + ); + my $value = $cron->get("workflowId") if defined $cron; + $f->workflow( + name=>"workflowId", + value=>$value, + label=>$i18n->get("workflow"), + hoverHelp=>$i18n->get("workflow help") + ); + my %priorities = (); + tie %priorities, 'Tie::IxHash'; + %priorities = (1=>$i18n->get("high"), 2=>$i18n->get("medium"), 3=>$i18n->get("low")); + my $value = $cron->get("priority") if defined $cron; + $f->radioList( + name=>"priority", + vertical=>1, + value=>$value, + defaultValue=>2, + options=>\%priorities, + label=>$i18n->get("priority"), + hoverHelp=>$i18n->get("priority help") + ); + my $value = $cron->get("minuteOfHour") if defined $cron; + $f->text( + name=>"minuteOfHour", + value=>$value, + defaultValue=>0, + label=>$i18n->get("minute of hour"), + hoverHelp=>$i18n->get("minute of hour help") + ); + my $value = $cron->get("hourOfDay") if defined $cron; + $f->text( + name=>"hourOfDay", + value=>$value, + defaultValue=>"*", + label=>$i18n->get("hour of day"), + hoverHelp=>$i18n->get("hour of day help") + ); + my $value = $cron->get("dayOfMonth") if defined $cron; + $f->text( + name=>"dayOfMonth", + value=>$value, + defaultValue=>"*", + label=>$i18n->get("day of month"), + hoverHelp=>$i18n->get("day of month help") + ); + my $value = $cron->get("monthOfYear") if defined $cron; + $f->text( + name=>"monthOfYear", + value=>$value, + defaultValue=>"*", + label=>$i18n->get("month of year"), + hoverHelp=>$i18n->get("month of year help") + ); + my $value = $cron->get("dayOfWeek") if defined $cron; + $f->text( + name=>"dayOfWeek", + value=>$value, + defaultValue=>"*", + label=>$i18n->get("day of week"), + hoverHelp=>$i18n->get("day of week help") + ); + $f->submit; + return WebGUI::AdminConsole->new($session,"cron")->render($f->print); +} + + +#------------------------------------------------------------------- + +=head2 www_manageCron ( ) + +Display a list of the scheduler activities. + +=cut + +sub www_manageCron { + my $session = shift; + return $session->privilege->adminOnly() unless ($session->user->isInGroup(3)); + my $i18n = WebGUI::International->new($session, "Workflow_Cron"); + my $output = ''; + my $rs = $session->db->read("select taskId, title, concat(minuteOfHour, hourOfDay, dayOfMonth, monthOfYear, dayOfWeek), enabled from WorkflowSchedule"); + while (my ($id, $title, $schedule, $enabled) = $rs->array) { + $output .= '\n"; + } + $output .= '
' + .$session->icon->delete("op=deleteCronJob;id=".$id, undef, $i18n->get("are you sure you want to delete this scheduled task")) + .$session->icon->edit("op=editCronJob;id=".$id) + .''.$title.''.$schedule.'' + .($enabled ? "X" : "") + ."
'; + return WebGUI::AdminConsole->new($session,"cron")->render($output); +} + +1; diff --git a/lib/WebGUI/i18n/English/Form_Captcha.pm b/lib/WebGUI/i18n/English/Form_Captcha.pm index 15512e60e..92b87cfb9 100644 --- a/lib/WebGUI/i18n/English/Form_Captcha.pm +++ b/lib/WebGUI/i18n/English/Form_Captcha.pm @@ -1,7 +1,7 @@ package WebGUI::i18n::English::Form_Captcha; our $I18N = { - 'formName' => { + 'topicName' => { message => q|Captcha|, context => q|Captcha is an acronym, it cannot be translated.|, lastUpdated => 1131394072, diff --git a/lib/WebGUI/i18n/English/Workflow_Cron.pm b/lib/WebGUI/i18n/English/Workflow_Cron.pm new file mode 100644 index 000000000..f73cde6dd --- /dev/null +++ b/lib/WebGUI/i18n/English/Workflow_Cron.pm @@ -0,0 +1,156 @@ +package WebGUI::i18n::English::Workflow_Cron; + +our $I18N = { + 'day of week help' => { + message => q|Which day of the week do you want this workflow triggered? The range is between 0 and 6 where 0 is Sunday. You can specify a specific day like "0" or "2". You may also specify all days of the week by "*". And finally you can specify a list of days of the week like "1,5,6".|, + context => q|the hover help for the month of year field|, + lastUpdated => 0, + }, + + 'day of week' => { + message => q|Day of Week|, + context => q|The day of week field.|, + lastUpdated => 0, + }, + + 'month of year help' => { + message => q|Which month of the year do you want this workflow triggered? The range is between 1 and 31. You can specify a specific month like "2" or 12". You may also specify all months by "*". You can specify intervals like "*/3" (every 3 months). And finally you can specify a list of months like "1,5,11".|, + context => q|the hover help for the month of year field|, + lastUpdated => 0, + }, + + 'month of year' => { + message => q|Month of Year|, + context => q|The month field.|, + lastUpdated => 0, + }, + + 'day of month help' => { + message => q|Which day of the month do you want this workflow triggered? The range is between 1 and 31. You can specify a specific day like "2" or 12". You may also specify all days by "*". You can specify intervals like "*/3" (every 3 days). And finally you can specify a list of days like "1,5,11".|, + context => q|the hover help for the day of month field|, + lastUpdated => 0, + }, + + 'day of month' => { + message => q|Day of Month|, + context => q|The day field.|, + lastUpdated => 0, + }, + + 'hour of day help' => { + message => q|Which hour of the day do you want this workflow triggered? The range is between 0 and 23. You can specify a specific hour like "0" or 12". You may also specify all hours by "*". You can specify intervals like "*/3" (every 3 hours). And finally you can specify a list of hours like "1,5,17,21".|, + context => q|the hover help for the hour of day field|, + lastUpdated => 0, + }, + + 'hour of day' => { + message => q|Hour of Day|, + context => q|The hour field.|, + lastUpdated => 0, + }, + + 'minute of hour help' => { + message => q|Which minute of the hour do you want this workflow triggered? The range is between 0 and 59. You can specify a specific minute like "0" or 12". You may also specify all minutes by "*". You can specify intervals like "*/3" (every 3 minutes). And finally you can specify a list of minutes like "1,5,17,24".|, + context => q|the hover help for the minute of hour field|, + lastUpdated => 0, + }, + + 'minute of hour' => { + message => q|Minute of Hour|, + context => q|The minute field.|, + lastUpdated => 0, + }, + + 'run once help' => { + message => q|If this is set to yes, then the task will be executed at the scheduled time, and then will delete itself.|, + context => q|the hover help for the run once field|, + lastUpdated => 0, + }, + + 'run once' => { + message => q|Run Once?|, + context => q|Yes or no question asking the user if this cron job should delete itself after the first execution.|, + lastUpdated => 0, + }, + + 'enabled help' => { + message => q|If this is set to yes, then the workflow will be kicked off at the scheduled time.|, + context => q|the hover help for the enabled field|, + lastUpdated => 0, + }, + + 'enabled' => { + message => q|Enabled?|, + context => q|Yes or no question asking the user if this cron job is enabled.|, + lastUpdated => 0, + }, + + 'workflow help' => { + message => q|Choose a workflow that you wish to execute at the scheduled time.|, + context => q|the hover help for the workflow field|, + lastUpdated => 0, + }, + + 'workflow' => { + message => q|Workflow|, + context => q|A label indicating to the user that they should select a workflow.|, + lastUpdated => 0, + }, + + 'title help' => { + message => q|A human readable label to easily identify what this task does.|, + context => q|the hover help for the title field|, + lastUpdated => 0, + }, + + 'title' => { + message => q|Title|, + context => q|A human readable label to identify a cron job.|, + lastUpdated => 0, + }, + + 'priority help' => { + message => q|This determines the priority level of the workflow to be executed. Normally this should be left at "medium". If the workflow needs urgent execcution, then set it to "high". If it's a maintenance task and can be put off until the server is less busy, then set it to "low"|, + context => q|the hover help for the priority|, + lastUpdated => 0, + }, + + 'priority' => { + message => q|Priority|, + context => q|A level of urgency for a workflow to be executed under.|, + lastUpdated => 0, + }, + + 'low' => { + message => q|Low|, + context => q|The least amount of priority.|, + lastUpdated => 0, + }, + + 'high' => { + message => q|High|, + context => q|The greatest priority.|, + lastUpdated => 0, + }, + + 'medium' => { + message => q|Medium|, + context => q|Mid range priority.|, + lastUpdated => 0, + }, + + 'topicName' => { + message => q|Scheduler|, + context => q|The title of the cron/scheduler interface.|, + lastUpdated => 0, + }, + + 'are you sure you wish to delete this scheduled task' => { + message => q|Are you certain you wish to delete this scheduled task?|, + context => q|prompt when a user is about to delete the cron job|, + lastUpdated => 0, + }, + +}; + +1;