From b911f051253527906394196ec81b4f01b11fd663 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 3 Jan 2011 17:01:26 -0800 Subject: [PATCH] Commit events created by the ExtendCalendarRecurrences workflow activity. Fixes bug #11994. --- docs/changelog/7.x.x.txt | 1 + .../Activity/ExtendCalendarRecurrences.pm | 14 ++++++++-- .../Activity/ExtendCalendarRecurrences.t | 28 ++++++++++++------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a7ed982a9..214efc408 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -14,6 +14,7 @@ - fixed #12010: Related URLs are not copied for events created through recurrence - fixed #12012: WebGUI Account system does not present login to visitors for proper redirect - fixed #12015: Thingy: Custom 'File' form fields get deleted upon save + - fixed #11994: recurring calendar entries 7.10.6 - fixed #11974: Toolbar icons unclickable in Webkit using HTML5 diff --git a/lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm b/lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm index 26fa4fae8..465b3cb2e 100644 --- a/lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm +++ b/lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm @@ -19,6 +19,7 @@ use strict; use base 'WebGUI::Workflow::Activity'; use WebGUI::International; use WebGUI::Asset; +use WebGUI::VersionTag; use DateTime; =head1 NAME @@ -171,18 +172,25 @@ sub processRecurrence { } my $recur = $event->getRecurrence; + my $versionTag = WebGUI::VersionTag->create($self->session, {name => 'Extend Calendar Recurrence for assetId '.$event->getId, }); + $versionTag->setWorking(); my $start = $event->getDateTimeStart->truncate(to => 'day'); my $limit = DateTime->today->add( years => 2 ); my $end = $event->limitedEndDate($limit); my $set = $event->dateSet( $recur, $start, $end ); my $i = $set->iterator; - while ( my $d = $i->next ) { - return if ( time > $timeLimit ); + my $time_limit = 0; + DATE: while ( my $d = $i->next ) { + if ( time > $timeLimit ) { + $time_limit = 1; + last DATE; + } $event->generateRecurrence($d); } - return 1; + $versionTag->commit; + return $time_limit ? 1 : 0; } ## end sub processRecurrence 1; diff --git a/t/Workflow/Activity/ExtendCalendarRecurrences.t b/t/Workflow/Activity/ExtendCalendarRecurrences.t index 5f8c6ca13..7bb514eec 100644 --- a/t/Workflow/Activity/ExtendCalendarRecurrences.t +++ b/t/Workflow/Activity/ExtendCalendarRecurrences.t @@ -38,9 +38,13 @@ my $event = $calendar->addChild( { className => 'WebGUI::Asset::Event', startDate => $one_year_ago, endDate => $one_year_ago, - } + }, undef, undef, {skipAutoCommitWorkflows => 1, } ); +$tag->commit; +$calendar = $calendar->cloneFromDb; +$event = $event->cloneFromDb; + my $recurId = $event->setRecurrence( { recurType => 'monthDay', every => 2, @@ -87,17 +91,21 @@ while (my $status = $instance->run ne 'complete') { $instance->run; } -my $sql = q{ - select e.startDate, e.endDate - from asset a - inner join Event e on e.assetId = a.assetId - and a.parentId = ? - order by e.startDate -}; +#my $sql = q{ +# select e.startDate, e.endDate +# from asset a +# inner join Event e on e.assetId = a.assetId +# and a.parentId = ? +# order by e.startDate +#}; -my $dates = $session->db->buildArrayRefOfHashRefs($sql, [$calendar->getId]); +#my $dates = $session->db->buildArrayRefOfHashRefs($sql, [$calendar->getId]); +my $dates = $calendar->getLineage(['children'], { returnObjects => 1, }); # 3 years at every other month (6 times) plus the one we started with -is(@$dates, 19, 'created right number of dates') or diag Dumper $dates; +is(@{$dates}, 19, 'created right number of dates') or diag Dumper $dates; + +my @uncommitted_events = grep { $_->get('status') ne 'approved' } @{ $dates }; +is @uncommitted_events, 0, 'all events are committed (approved)'; done_testing;