From f3e340fa3a69f73efa6158c2f32200140db57a84 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 14 Feb 2011 16:37:06 -0800 Subject: [PATCH] Rework the CS mail fetching interval so that it can't have crazy values like never, every second or yearly. Fixes bug #12043 --- docs/changelog/7.x.x.txt | 1 + docs/upgrades/upgrade_7.10.9-7.10.10.pl | 28 ++++ lib/WebGUI/Asset/Wobject/Collaboration.pm | 120 ++++++++++++++++-- .../i18n/English/Asset_Collaboration.pm | 60 +++++++++ 4 files changed, 198 insertions(+), 11 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 85ba253d8..76d2772ca 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed #12035: Story Manager - make keywords from Story view work - fixed #12042: userDefined variables have no template variable help - fixed #12045: Job listing template, missing summary + - fixed #12043: Collaboration Systems don't pull mail that fast! 7.10.9 - fixed #12030: Calendar Feed Time Zone Issue diff --git a/docs/upgrades/upgrade_7.10.9-7.10.10.pl b/docs/upgrades/upgrade_7.10.9-7.10.10.pl index 88b9b922c..949801e8e 100644 --- a/docs/upgrades/upgrade_7.10.9-7.10.10.pl +++ b/docs/upgrades/upgrade_7.10.9-7.10.10.pl @@ -31,6 +31,7 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here +convertCsMailInterval($session); finish($session); # this line required @@ -44,6 +45,33 @@ finish($session); # this line required # print "DONE!\n" unless $quiet; #} +#---------------------------------------------------------------------------- +sub convertCsMailInterval { + my $session = shift; + print "\tConvert the getMailInterval from seconds to enumeration... " unless $quiet; + # and here's our code + $session->db->write('alter table Collaboration modify column getMailInterval char(64)'); + my $get_row = $session->db->read('select assetId, revisionDate, getMailInterval from Collaboration'); + my $change_row = $session->db->prepare('update Collaboration set getMailInterval=? where assetId=? and revisionDate=?'); + while (my ($assetId, $revisionDate, $seconds ) = $get_row->array) { + my $interval; + if ($seconds <= 60) { $interval = 'every minute'; } + elsif ($seconds <= 120) { $interval = 'every other minute'; } + elsif ($seconds <= 300) { $interval = 'every 5 minutes'; } + elsif ($seconds <= 600) { $interval = 'every 10 minutes'; } + elsif ($seconds <= 900) { $interval = 'every 15 minutes'; } + elsif ($seconds <= 1200) { $interval = 'every 20 minutes'; } + elsif ($seconds <= 1800) { $interval = 'every 30 minutes'; } + elsif ($seconds <= 3600) { $interval = 'every hour'; } + elsif ($seconds <= 7200) { $interval = 'every other hour'; } + else { $interval = 'once per day'; } + $change_row->execute([$interval, $assetId, $revisionDate]); + } + $get_row->finish; + $change_row->finish; + print "DONE!\n" unless $quiet; +} + # -------------- DO NOT EDIT BELOW THIS LINE -------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 9650db67a..fa06c0873 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -418,19 +418,19 @@ sub commit { unless (defined $cron) { $cron = WebGUI::Workflow::Cron->create($self->session, { title=>$self->getTitle." ".$i18n->get("mail"), - minuteOfHour=>"*/".($self->get("getMailInterval")/60), className=>(ref $self), methodName=>"new", parameters=>$self->getId, - workflowId=>"csworkflow000000000001" + workflowId=>"csworkflow000000000001", + $self->getCronIntervals, }); $self->update({getMailCronId=>$cron->getId}); } - if ($self->get("getMail")) { - $cron->set({enabled=>1,title=>$self->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($self->get("getMailInterval")/60)}); - } else { - $cron->set({enabled=>0,title=>$self->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($self->get("getMailInterval")/60)}); - } + $cron->set({ + enabled => $self->get('getMail') ? 1 : 0, + title => $self->getTitle." ".$i18n->get("mail"), + $self->getCronIntervals(), + }); } #------------------------------------------------------------------- @@ -488,6 +488,20 @@ sub definition { ($useKarma? (karmaRank=>$i18n->get('karma rank')) : ()), ); + tie my %mailIntervalOptions, 'Tie::IxHash'; + %mailIntervalOptions = ( + 'every minute' => $i18n->get('every minute'), + "every other minute" => $i18n->get('every other minute'), + 'every 5 minutes' => $i18n->get('every 5 minutes'), + 'every 10 minutes' => $i18n->get('every 10 minutes'), + 'every 15 minutes' => $i18n->get('every 15 minutes'), + 'every 20 minutes' => $i18n->get('every 20 minutes'), + 'every 30 minutes' => $i18n->get('every 30 minutes'), + 'every hour' => $i18n->get('every hour'), + 'every other hour' => $i18n->get('every other hour'), + 'once per day' => $i18n->get('once per day'), + ); + my %properties; tie %properties, 'Tie::IxHash'; %properties = ( @@ -593,8 +607,11 @@ sub definition { hoverHelp=>$i18n->get("get mail help"), }, getMailInterval=>{ - fieldType=>"interval", - defaultValue=>300, + #fieldType=>"interval", + #defaultValue=>300, + fieldType=>"selectBox", + defaultValue => 'every 10 minutes', + options => \%mailIntervalOptions, tab=>'mail', label=>$i18n->get("get mail interval"), hoverHelp=>$i18n->get("get mail interval help"), @@ -921,11 +938,11 @@ sub duplicate { my $i18n = WebGUI::International->new($self->session, "Asset_Collaboration"); my $newCron = WebGUI::Workflow::Cron->create($self->session, { title=>$self->getTitle." ".$i18n->get("mail"), - minuteOfHour=>"*/".($self->get("getMailInterval")/60), className=>(ref $self), methodName=>"new", parameters=>$self->getId, - workflowId=>"csworkflow000000000001" + workflowId=>"csworkflow000000000001", + $self->getCronIntervals(), }); $newAsset->update({getMailCronId=>$newCron->getId}); $newAsset->incrementReplies('',''); @@ -949,6 +966,87 @@ sub duplicateBranch { #------------------------------------------------------------------- +=head2 getCronIntervals + +Translate the settings for getCsMailInterval into options for Spectre's Cron, +minuteOfHour, hourOfDay and so on. + +Returns a hash of those options that can be folded into a hash of property settings for the +Cron job. + +=cut + +sub getCronIntervals { + my $self = shift; + my $interval = $self->get('getMailInterval'); + ##My kingdom for a switch statement! + if ($interval eq 'every minute') { + return( + hourOfDay => '*', + minuteOfHour => '*/1', + ); + } + elsif ($interval eq 'every other minute') { + return( + hourOfDay => '*', + minuteOfHour => '*/2', + ); + } + elsif ($interval eq 'every 5 minutes') { + return( + hourOfDay => '*', + minuteOfHour => '*/5', + ); + } + elsif ($interval eq 'every 10 minutes') { + return( + hourOfDay => '*', + minuteOfHour => '*/10', + ); + } + elsif ($interval eq 'every 15 minutes') { + return( + hourOfDay => '*', + minuteOfHour => '*/15', + ); + } + elsif ($interval eq 'every 20 minutes') { + return( + hourOfDay => '*', + minuteOfHour => '*/20', + ); + } + elsif ($interval eq 'every 30 minutes') { + return( + hourOfDay => '*', + minuteOfHour => '*/30', + ); + } + elsif ($interval eq 'every hour') { + return( + hourOfDay => '*', + minuteOfHour => '0', + ); + } + elsif ($interval eq 'every other hour') { + return( + hourOfDay => '*/2', + minuteOfHour => '0', + ); + } + elsif ($interval eq 'once per day') { + return( + hourOfDay => '7', + minuteOfHour => '0', + ); + } + return( + minuteOfHour => '*/10', + ); +} + +#------------------------------------------------------------------- + =head2 getEditTabs Add a tab for the mail interface. diff --git a/lib/WebGUI/i18n/English/Asset_Collaboration.pm b/lib/WebGUI/i18n/English/Asset_Collaboration.pm index 414bb4a9b..42bccecde 100644 --- a/lib/WebGUI/i18n/English/Asset_Collaboration.pm +++ b/lib/WebGUI/i18n/English/Asset_Collaboration.pm @@ -1749,6 +1749,66 @@ the Collaboration Asset, the user will be notified.|, lastUpdated => 0, }, + 'every minute' => { + message => q{Every minute}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every other minute' => { + message => q{Every other minute}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every 5 minutes' => { + message => q{Every 5 minutes}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every 10 minutes' => { + message => q{Every 10 minutes}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every 15 minutes' => { + message => q{Every 15 minutes}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every 20 minutes' => { + message => q{Every 20 minutes}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every 30 minutes' => { + message => q{Every 30 minutes}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every hour' => { + message => q{Every hour}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'every other hour' => { + message => q{Every other hour}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + + 'once per day' => { + message => q{Once per day}, + context => q{label in the asset edit form}, + lastUpdated => 0, + }, + }; 1;