DateTime::Event::ICal in Calendar, workflow to extend recurrence
This commit is contained in:
parent
01f0250d28
commit
c356a7acc6
8 changed files with 825 additions and 641 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
7.9.2
|
7.9.2
|
||||||
|
- added: Workflow to extend recurring Calendar events 2 years from the
|
||||||
|
current date (now part of weekly maintenence)
|
||||||
|
- new dependency: DateTime::Event::ICal
|
||||||
- fixed #11507: Spectre Reports Wrong Workflow Count
|
- fixed #11507: Spectre Reports Wrong Workflow Count
|
||||||
- added #11412: Additional navigation in Gallery Photo View
|
- added #11412: Additional navigation in Gallery Photo View
|
||||||
- added: Sort Items switch to Syndicated Content asset
|
- added: Sort Items switch to Syndicated Content asset
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ my $session = start(); # this line required
|
||||||
# upgrade functions go here
|
# upgrade functions go here
|
||||||
addSortItemsSCColumn($session);
|
addSortItemsSCColumn($session);
|
||||||
removeTranslationCruft($session);
|
removeTranslationCruft($session);
|
||||||
|
addExtensionWorkflow($session);
|
||||||
|
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
|
|
@ -48,6 +49,17 @@ sub removeTranslationCruft {
|
||||||
print "DONE!\n" unless $quiet;
|
print "DONE!\n" unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub addExtensionWorkflow {
|
||||||
|
print "\tAdding calendar event extension to weekly maintenence..."
|
||||||
|
unless $quiet;
|
||||||
|
my $workflow = WebGUI::Workflow->new($session, 'pbworkflow000000000002');
|
||||||
|
my $activity = $workflow->addActivity('WebGUI::Workflow::Activity::ExtendCalendarRecurrences');
|
||||||
|
$activity->set(title => 'Extend Calendar Recurrences');
|
||||||
|
$activity->set(description => 'Create events for live recurrences up to two years from the current date');
|
||||||
|
print "Done\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub addSortItemsSCColumn {
|
sub addSortItemsSCColumn {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
185
lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm
Normal file
185
lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
package WebGUI::Workflow::Activity::ExtendCalendarRecurrences;
|
||||||
|
|
||||||
|
=head1 LEGAL
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
WebGUI is Copyright 2001-2009 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
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'WebGUI::Workflow::Activity';
|
||||||
|
use WebGUI::International;
|
||||||
|
use WebGUI::Asset;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
WebGUI::Workflow::Activity::ExtendCalendarRecurrences
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
Generates events for all active calendar recurring events up to 2 years in the
|
||||||
|
future.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
See WebGUI::Workflow::Activity for details on how to use any activity.
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
These methods are available from this class:
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 definition ( session, definition )
|
||||||
|
|
||||||
|
See WebGUI::Workflow::Activity::definition() for details.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub definition {
|
||||||
|
my ( $class, $session, $definition ) = @_;
|
||||||
|
my $i18n = WebGUI::International->new( $session, 'Activity_ExtendCalendarRecurrences' );
|
||||||
|
push( @$definition, { name => $i18n->get('topicName') } );
|
||||||
|
return $class->SUPER::definition( $session, $definition );
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 execute ( [ object ] )
|
||||||
|
|
||||||
|
See WebGUI::Workflow::Activity::execute() for details.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub execute {
|
||||||
|
my ( $self, $obj, $instance ) = @_;
|
||||||
|
my $timeLimit = time + 55;
|
||||||
|
|
||||||
|
my $piped = $instance->getScratch('recurrences')
|
||||||
|
|| $self->generateRecurrenceList();
|
||||||
|
|
||||||
|
while (time < $timeLimit ) {
|
||||||
|
return $self->COMPLETE unless $piped;
|
||||||
|
my ( $recurId, $rest ) = split /\|/, $piped, 2;
|
||||||
|
|
||||||
|
$self->processRecurrence( $recurId, $timeLimit )
|
||||||
|
and $piped = $rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
$instance->setScratch( recurrences => $piped );
|
||||||
|
return $self->WAITING(1);
|
||||||
|
} ## end sub execute
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 findRecurrenceIds ( calendarId )
|
||||||
|
|
||||||
|
Find all recurIds for the given calendarId.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub findRecurrenceIds {
|
||||||
|
my ( $self, $calendarId ) = @_;
|
||||||
|
my $sql = q{
|
||||||
|
SELECT r.recurId
|
||||||
|
FROM Event_recur r
|
||||||
|
INNER JOIN Event e ON r.recurId = e.recurId
|
||||||
|
INNER JOIN asset a ON e.assetId = a.assetId
|
||||||
|
WHERE a.parentId = ?
|
||||||
|
};
|
||||||
|
return $self->session->db->buildArrayRef( $sql, [ $calendarId ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 findCalendarIds
|
||||||
|
|
||||||
|
Returns an arrayref of assetIds for all Calendar assets in the asset tree.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub findCalendarIds {
|
||||||
|
my $self = shift;
|
||||||
|
my $root = WebGUI::Asset->getRoot( $self->session );
|
||||||
|
return $root->getLineage( ['descendants'], { includeOnlyClasses => ['WebGUI::Asset::Wobject::Calendar'] } );
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 findLastEventId ( recurId )
|
||||||
|
|
||||||
|
Returns the assetId of the most WebGUI::Asset::Event generated for the given
|
||||||
|
recurrence.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub findLastEventId {
|
||||||
|
my ( $self, $recurId ) = @_;
|
||||||
|
my $sql = q{
|
||||||
|
SELECT assetId
|
||||||
|
FROM Event
|
||||||
|
WHERE recurId = ?
|
||||||
|
ORDER BY startDate
|
||||||
|
LIMIT 1
|
||||||
|
};
|
||||||
|
return $self->session->db->quickScalar( $sql, [$recurId] );
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 generateRecurrenceList ()
|
||||||
|
|
||||||
|
Returns a string of pipe-seperated recurrence IDs for all the calendars in the
|
||||||
|
asset tree. This is called exactly once per workflow instance.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub generateRecurrenceList {
|
||||||
|
my $self = shift;
|
||||||
|
return join( '|', map { @{ $self->findRecurrenceIds($_) } } @{ $self->findCalendarIds } );
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 processRecurrence (recurId, timeLimit)
|
||||||
|
|
||||||
|
Generates as many WebGUI::Asset::Event objects as it can before timeLimit is
|
||||||
|
up or the recurrence is finished for the given recurId. Returns true if it
|
||||||
|
exhausted the recurrence, false otherwise.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub processRecurrence {
|
||||||
|
my ( $self, $recurId, $timeLimit ) = @_;
|
||||||
|
my $eventId = $self->findLastEventId($recurId);
|
||||||
|
my $event = WebGUI::Asset::Event->new( $self->session, $eventId );
|
||||||
|
my $recur = $event->getRecurrence;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
$event->generateRecurrence($d);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
} ## end sub processRecurrence
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package WebGUI::i18n::English::Activity_ExtendCalendarRecurrences;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
our $I18N = {
|
||||||
|
'topicName' => {
|
||||||
|
message => q{Extend Calendar Recurrences},
|
||||||
|
lastUpdated => 1270240660,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
#vim:ft=perl
|
||||||
|
|
@ -138,6 +138,7 @@ checkModule("Readonly", "1.03" );
|
||||||
checkModule("Business::PayPal::API", "0.62" );
|
checkModule("Business::PayPal::API", "0.62" );
|
||||||
checkModule("Locales", "0.10" );
|
checkModule("Locales", "0.10" );
|
||||||
checkModule("Test::Harness", "3.17" );
|
checkModule("Test::Harness", "3.17" );
|
||||||
|
checkModule("DateTime::Event::ICal", "0.10" );
|
||||||
|
|
||||||
failAndExit("Required modules are missing, running no more checks.") if $missingModule;
|
failAndExit("Required modules are missing, running no more checks.") if $missingModule;
|
||||||
|
|
||||||
|
|
|
||||||
81
t/Asset/Event/recur.t
Normal file
81
t/Asset/Event/recur.t
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
# vim:syntax=perl
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# WebGUI is Copyright 2001-2009 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
|
||||||
|
#------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Tests the recurrence functionality of calendar events
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
use lib "$FindBin::Bin/../../../lib";
|
||||||
|
|
||||||
|
use Test::More;
|
||||||
|
use DateTime;
|
||||||
|
use WebGUI::Asset::Event;
|
||||||
|
|
||||||
|
my $startDate = DateTime->new(
|
||||||
|
year => 2000,
|
||||||
|
month => 1,
|
||||||
|
day => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
sub recur {
|
||||||
|
my ($type, $interval, $count, @extra) = @_;
|
||||||
|
my $r = {
|
||||||
|
recurType => $type,
|
||||||
|
every => $interval,
|
||||||
|
endAfter => $count,
|
||||||
|
@extra,
|
||||||
|
};
|
||||||
|
return [
|
||||||
|
map {$_->ymd} WebGUI::Asset::Event->dateSet($r, $startDate)->as_list
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
is_deeply recur(daily => 3 => 5), [
|
||||||
|
'2000-01-01', '2000-01-04', '2000-01-07', '2000-01-10', '2000-01-13',
|
||||||
|
];
|
||||||
|
|
||||||
|
is_deeply recur(weekday => 3 => 5), [
|
||||||
|
'2000-01-05', '2000-01-10', '2000-01-13', '2000-01-18', '2000-01-21',
|
||||||
|
];
|
||||||
|
|
||||||
|
is_deeply recur(weekly => 2 => 10 => dayNames => [qw(m w f)]), [
|
||||||
|
'2000-01-10', '2000-01-12', '2000-01-14',
|
||||||
|
'2000-01-24', '2000-01-26', '2000-01-28',
|
||||||
|
'2000-02-07', '2000-02-09', '2000-02-11', '2000-02-21'
|
||||||
|
];
|
||||||
|
|
||||||
|
is_deeply recur(monthDay => 3 => 4 => dayNumber => 4), [
|
||||||
|
'2000-01-04', '2000-04-04', '2000-07-04', '2000-10-04'
|
||||||
|
];
|
||||||
|
|
||||||
|
is_deeply recur(monthWeek => 1 => 6 => dayNames => ['w'], weeks => ['fifth']), [
|
||||||
|
'2000-01-26', '2000-02-23', '2000-03-29',
|
||||||
|
'2000-04-26', '2000-05-31', '2000-06-28',
|
||||||
|
];
|
||||||
|
|
||||||
|
is_deeply recur(yearDay => 2 => 3, months => ['feb'], dayNumber => 2), [
|
||||||
|
'2000-02-02', '2002-02-02', '2004-02-02',
|
||||||
|
];
|
||||||
|
|
||||||
|
my %labor_day = (
|
||||||
|
months => ['sep'],
|
||||||
|
weeks => ['first'],
|
||||||
|
dayNames => ['m'],
|
||||||
|
);
|
||||||
|
is_deeply recur(yearWeek => 3 => 3, %labor_day), [
|
||||||
|
'2000-09-04', '2003-09-01', '2006-09-04'
|
||||||
|
];
|
||||||
|
|
||||||
|
done_testing;
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
#vim:ft=perl
|
||||||
102
t/Workflow/Activity/ExtendCalendarRecurrences.t
Normal file
102
t/Workflow/Activity/ExtendCalendarRecurrences.t
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
# vim:syntax=perl
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# WebGUI is Copyright 2001-2009 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 lib "$FindBin::Bin/../../t/lib";
|
||||||
|
use Test::More;
|
||||||
|
use WebGUI::Test;
|
||||||
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Workflow::Activity::ExtendCalendarRecurrences;
|
||||||
|
use DateTime;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
my $session = WebGUI::Test->session;
|
||||||
|
my $temp = WebGUI::Asset->getTempspace($session);
|
||||||
|
|
||||||
|
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||||
|
WebGUI::Test::addToCleanup($tag);
|
||||||
|
|
||||||
|
my $calendar = $temp->addChild(
|
||||||
|
{ className => 'WebGUI::Asset::Wobject::Calendar' }
|
||||||
|
);
|
||||||
|
|
||||||
|
my $one_year_ago = DateTime->today->subtract(years => 1)->ymd;
|
||||||
|
|
||||||
|
my $event = $calendar->addChild(
|
||||||
|
{ className => 'WebGUI::Asset::Event',
|
||||||
|
startDate => $one_year_ago,
|
||||||
|
endDate => $one_year_ago,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
my $recurId = $event->setRecurrence(
|
||||||
|
{ recurType => 'monthDay',
|
||||||
|
every => 2,
|
||||||
|
startDate => $event->get('startDate'),
|
||||||
|
dayNumber => DateTime->today->day,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
my $workflow = WebGUI::Workflow->create(
|
||||||
|
$session, {
|
||||||
|
enabled => 1,
|
||||||
|
objectType => 'None',
|
||||||
|
mode => 'realtime',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
WebGUI::Test::addToCleanup($workflow);
|
||||||
|
|
||||||
|
my $activity =
|
||||||
|
$workflow->addActivity('WebGUI::Workflow::Activity::ExtendCalendarRecurrences');
|
||||||
|
|
||||||
|
my $calendars = [ $calendar->getId ];
|
||||||
|
{
|
||||||
|
# We only want to be testing our calendar, not any others in the asset
|
||||||
|
# tree.
|
||||||
|
no warnings 'redefine';
|
||||||
|
sub WebGUI::Workflow::Activity::ExtendCalendarRecurrences::findCalendarIds {
|
||||||
|
return $calendars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is $activity->findCalendarIds, $calendars, 'mocking worked';
|
||||||
|
|
||||||
|
my $instance = WebGUI::Workflow::Instance->create(
|
||||||
|
$session, {
|
||||||
|
workflowId => $workflow->getId,
|
||||||
|
skipSpectreNotification => 1,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
while (my $status = $instance->run ne 'complete') {
|
||||||
|
note $status;
|
||||||
|
$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 $dates = $session->db->buildArrayRefOfHashRefs($sql, [$calendar->getId]);
|
||||||
|
# 3 years at every other month (6 times) plus the one we started with
|
||||||
|
is(@$dates, 19) or diag Dumper $dates;
|
||||||
|
|
||||||
|
done_testing;
|
||||||
|
|
||||||
|
#vim:ft=perl
|
||||||
Loading…
Add table
Add a link
Reference in a new issue