Skip to content

Commit

Permalink
Fix Cron issues with CSes. Fixes bug #11284.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Nov 30, 2009
1 parent e614fc1 commit d535e74
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
7.7.28
- fixed #11278: Wrong test for Template::Toolkit in testEnvironment.pl
- fixed #11282: USPS Shipping Driver does not accept ZIP+4
- fixed #11284: Collaboration System Cron jobs for email

7.7.27
- fixed #11134: Tree Navigation menu colapses sub items of current page, missing JS files added
Expand Down
44 changes: 44 additions & 0 deletions docs/upgrades/upgrade_7.7.27-7.7.28.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ BEGIN
use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::Asset;
use WebGUI::Workflow::Cron;
use WebGUI::Asset::Wobject::Collaboration;


my $toVersion = '7.7.28';
Expand All @@ -31,6 +33,8 @@ BEGIN
my $session = start(); # this line required

# upgrade functions go here
clearOrphanedCSMailCronJobs($session);
deleteExtraCronJobsForCS($session);

finish($session); # this line required

Expand All @@ -44,6 +48,46 @@ BEGIN
# print "DONE!\n" unless $quiet;
#}

#----------------------------------------------------------------------------
# Describe what our function does
sub clearOrphanedCSMailCronJobs {
my $session = shift;
print "\tClear orphaned csworkflow000000000001 Cron Jobs with no CS attached... " unless $quiet;
my $crons = WebGUI::Workflow::Cron->getAllTasks($session);
##This section of code handles cron jobs created for CS'es where the revision of the
##CS with the cron has been deleted.
CRON: foreach my $cron (@{ $crons }) {
next CRON unless $cron->get('workflowId') eq 'csworkflow000000000001';
my $assetId = $cron->get('parameters');
my $asset = WebGUI::Asset->newByDynamicClass($session, $assetId);
next CRON if $asset;
print "\n\t\tDeleting ".$cron->get('title') unless $quiet;
$cron->delete;
}
print "\tDONE!\n" unless $quiet;
}

#----------------------------------------------------------------------------
# Describe what our function does
sub deleteExtraCronJobsForCS {
my $session = shift;
print "\tGuarantee that each CS has one and only one Cron job. Older jobs will be deleted... " unless $quiet;
my $cses = WebGUI::Asset::Wobject::Collaboration->getIsa($session);
CS: while( my $cs = $cses->() ) {
my @cronIds = $session->db->buildArray('select distinct(getMailCronId) from Collaboration where assetId=?',[$cs->getId]);
next CS unless @cronIds > 1;
my @oldCronIds = grep { $_ ne $cs->get('getMailCronId') } @cronIds;
CRON: foreach my $cronId (@oldCronIds) {
my $cron = WebGUI::Workflow::Cron->new($session, $cronId);
next CRON unless $cron;
print "\n\t\tDeleting ".$cron->get('title') unless $quiet;
$cron->delete;
}
$session->db->write('update Collaboration set getMailCronId=? where assetId=?', [$cs->get('getMailCronId'), $cs->getId]);
}
print "\tDONE!\n" unless $quiet;
}


# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------

Expand Down
10 changes: 10 additions & 0 deletions lib/WebGUI/Asset/Wobject/Collaboration.pm
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,16 @@ sub duplicate {
my $self = shift;
my $newAsset = $self->next::method(@_);
$newAsset->createSubscriptionGroup;
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"
});
$self->update({getMailCronId=>$newCron->getId});
return $newAsset;
}

Expand Down
31 changes: 12 additions & 19 deletions t/Asset/Wobject/Collaboration.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------

# XXX I (chrisn) started this file to test the features I added to the
# Collaboration / Post system for 7.5, but didn't have the time available to me
# to do a full test suite for the Collaboration Wobject. This means that this
# test suite is *largely incomplete* and should be finished. What is here *is*
# the following:
#
#
# 1. The basic framework for a test suite for the Collaboration Wobject.
# Includes setup, cleanup, boilerplate, etc. Basically the really boring,
# repetitive parts of the test that you don't want to write yourself.
# 2. The tests for the features I've implemented; namely, the groupToEditPost
# functionality.

use FindBin;
use strict;
use lib "$FindBin::Bin/../../lib";
Expand All @@ -32,7 +19,7 @@ use WebGUI::Asset::Wobject::Collaboration;
use WebGUI::Asset::Post;
use WebGUI::Asset::Wobject::Layout;
use Data::Dumper;
use Test::More tests => 10; # increment this value for each test you create
use Test::More tests => 13; # increment this value for each test you create

my $session = WebGUI::Test->session;

Expand All @@ -41,6 +28,7 @@ my $node = WebGUI::Asset->getImportNode($session);

# grab a named version tag
my $versionTag = WebGUI::VersionTag->getWorking($session);
addToCleanup($versionTag);
$versionTag->set({name => 'Collaboration => groupToEditPost test'});

# place the collab system under a layout to ensure we're using the inherited groupIdEdit value
Expand All @@ -55,6 +43,10 @@ my $collab = $layout->addChild({
url => 'collab',
});

$versionTag->commit;
$collab = $collab->cloneFromDb;
ok($session->id->valid($collab->get('getMailCronId')), 'commited CS has a cron job created for it');

# Test for a sane object type
isa_ok($collab, 'WebGUI::Asset::Wobject::Collaboration');

Expand Down Expand Up @@ -99,12 +91,13 @@ is($collab->getRssFeedUrl, '/collab?func=viewRss', 'getRssFeedUrl');
is($collab->getRdfFeedUrl, '/collab?func=viewRdf', 'getRdfFeedUrl');
is($collab->getAtomFeedUrl, '/collab?func=viewAtom', 'getAtomFeedUrl');

note "Mail Cron job tests";
my $dupedCollab = $collab->duplicate();
addToCleanup(WebGUI::VersionTag->new($session, $dupedCollab->get('tagId')));
ok($dupedCollab->get('getMailCronId'), 'Duplicated CS has a cron job');
isnt($dupedCollab->get('getMailCronId'), $collab->get('getMailCronId'), '... and it is different from its source asset');

TODO: {
local $TODO = "Tests to make later";
ok(0, 'A whole lot more work to do here');
}

END {
# Clean up after thyself
$versionTag->rollback();
}

0 comments on commit d535e74

Please sign in to comment.