Have the Calendar iCal feed pass along the timeZone of events. Fixes bug #12030.

Squashed commit of the following:

commit ce957db5311c7fb11c7d780b9f63c1b0adc17cda
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Mon Jan 31 19:00:23 2011 -0800

    Changelog notice for the ical bugfix with timezones.

commit 24a3bc1c74b20ca6ba689641fa0187b659dc3c5e
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Mon Jan 31 15:32:50 2011 -0800

    Transfer the time zone as one of the WebGUI specific items for the Event.

commit 36f87539ba8b090a5e5c9f1879cd40b6f6e69afc
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Sun Jan 30 21:18:12 2011 -0800

    Refactor the code so that the Event adds itself to a calendar object, giving it access to add other things to the calendar, like a timezone definition.

commit f401966bd53b51950f1402a5a19b92b13dcc6b06
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Sun Jan 30 19:42:49 2011 -0800

    Document which version of Data::ICal that we're now using.

commit 689522e30b26fc445da5b59b81789c0d72e157d4
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Sat Jan 29 14:27:25 2011 -0800

    Fix a typo in the Event preventing menuTitle from being sent out.  Fix issue with the menuTitle being set twice.  Update the test to fix long string handling.

commit 59043eee1536e60d92f23313a33dc54da6f15122
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Fri Jan 28 19:48:16 2011 -0800

    Move iCal generation over to Data::ICal.  Give each event the ability to return itself as an Data::ICal::Entry::Event object.

commit eec448b38c101b599c0fb695f442012e311385fb
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Fri Jan 28 19:47:14 2011 -0800

    Document new testing module.  It't only required if you're doing testing.

commit 3d1e82229423834330dcdd31c0a81df986df0f32
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Fri Jan 28 17:05:09 2011 -0800

    Fix setting the title in the iCal feed.

commit 458f4d2e0e1faa1cc6dcb7107040d06b51b97d36
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Fri Jan 28 13:37:52 2011 -0800

    Rewrite of CalendarUpdateFeeds to use Data::ICal

commit 1a271ebc78bbe8b21a26f7a0dba61d1462922f30
Author: Colin Kuskie <colink@perldreamer.com>
Date:   Fri Jan 28 10:49:27 2011 -0800

    Begin building an ICal object for parsing the ical feeds.
This commit is contained in:
Colin Kuskie 2011-01-31 19:05:04 -08:00
parent 93646ad8e6
commit 8ae16ba37c
8 changed files with 110 additions and 161 deletions

View file

@ -23,6 +23,7 @@ use WebGUI::Asset::Event;
use WebGUI::DateTime;
use DateTime::TimeZone;
use Data::Dumper;
use Data::ICal;
use LWP::UserAgent;
use JSON ();
@ -142,88 +143,52 @@ sub execute {
next FEED;
}
my $data = $response->content;
# If doesn't start with BEGIN:VCALENDAR then error
unless ($data =~ /^BEGIN:VCALENDAR/i) {
my $data = $response->content;
my $cal = Data::ICal->new( data => $data );
if (!$cal) {
# Update the result and last updated fields
$feed->{lastResult} = "Not an iCalendar feed";
$feed->{lastResult} = "Error parsing iCal feed";
$feed->{lastUpdated} = $dt;
$calendar->setFeed($feed->{feedId}, $feed);
next FEED;
#next FEED;
}
my $active = 0; # Parser on/off
my %current_event = ();
my %events;
my $line_number = 0;
$data =~ s/[ \t]?[\r\n]+[ \t]+/ /msg; #Process line continuations
LINE: for my $line (split /[\r\n]+/,$data) {
chomp $line;
$line_number++;
next unless $line =~ /\w/;
#warn "LINE $line_number: $line\n";
if ($line =~ /^BEGIN:VEVENT$/i) {
$active = 1;
next LINE;
}
elsif ($line =~ /^END:VEVENT$/i) {
$active = 0;
# Flush event
my $uid = lc $current_event{uid}[1];
delete $current_event{uid};
$events{$uid} = {%current_event};
$session->log->info( "Found event $uid from feed " . $feed->{feedId} );
%current_event = ();
next LINE;
}
else {
# Flush old entry
# KEY;ATTRIBUTE=VALUE;ATTRIBUTE=VALUE:KEYVALUE
my ($key_attrs,$value) = split /:/,$line,2;
my @attrs = $key_attrs ? (split /;/, $key_attrs) : ();
my $key = shift @attrs;
my %attrs;
while (my $attribute = shift @attrs) {
my ($attr_key, $attr_value) = split /=/, $attribute, 2;
$attrs{lc $attr_key} = $attr_value;
}
$current_event{lc $key} = [\%attrs,$value];
}
}
my $feedData = $feedList->{$feed->{feedId}} = {
added => 0,
updated => 0,
errored => 0,
assetId => $calendar->getId,
};
EVENT: for my $id (keys %events) {
EVENT: foreach my $entry (@{ $cal->entries }) {
next EVENT unless $entry->ical_entry_type eq 'VEVENT';
#use Data::Dumper;
#warn "EVENT: $id; ".Dumper $events{$id};
my $event_properties = $entry->properties;
# Prepare event data
my $properties = {
feedUid => $id,
feedId => $feed->{feedId},
description => _unwrapIcalText($events{$id}->{description}->[1]),
title => _unwrapIcalText($events{$id}->{summary}->[1]),
location => _unwrapIcalText($events{$id}->{location}->[1]),
menuTitle => substr($events{$id}->{summary}->[1],0,15),
className => 'WebGUI::Asset::Event',
isHidden => 1,
};
PROPERTY: foreach my $property (qw/uid description summary location/) {
next property unless exists $event_properties->{$property};
$properties->{$property} = $event_properties->{$property}->[0]->value;
}
##Fixup
$properties->{title} = delete $properties->{summary};
$properties->{feedUid} = delete $properties->{uid};
# Prepare the date
my $dtstart = $events{$id}->{dtstart}->[1];
my $dtstart = $event_properties->{dtstart}->[0]->value;
if ($dtstart =~ /T/) {
my ($date, $time) = split /T/, $dtstart;
my ($year, $month, $day) = $date =~ /(\d{4})(\d{2})(\d{2})/;
my ($hour, $minute, $second) = $time =~ /(\d{2})(\d{2})(\d{2})/;
my $tz = $events{$id}->{dtstart}->[0]->{tzid};
my $tz = '';
if ($event_properties->{dtstart}->[0]->properties->{tzid}) {
$tz = $event_properties->{dtstart}->[0]->properties->{tzid};
}
if (!$tz || !DateTime::TimeZone->is_valid_name($tz)) {
$tz = "UTC";
}
@ -253,14 +218,14 @@ sub execute {
next EVENT;
}
my $dtend = $events{$id}->{dtend}->[1];
my $duration = $events{$id}->{duration}->[1];
my $dtend = exists $event_properties->{dtend} ? $event_properties->{dtend}->[0]->value : undef;
my $duration = exists $event_properties->{duration} ? $event_properties->{duration}->[0]->value : undef;
if ($dtend =~ /T/) {
my ($date, $time) = split /T/, $dtend;
my ($year, $month, $day) = $date =~ /(\d{4})(\d{2})(\d{2})/;
my ($hour, $minute, $second) = $time =~ /(\d{2})(\d{2})(\d{2})/;
my $tz = $events{$id}->{dtend}->[0]->{tzid};
my $tz = '';
if (!$tz || !DateTime::TimeZone->is_valid_name($tz)) {
$tz = "UTC";
}
@ -330,28 +295,15 @@ sub execute {
}
# If there are X-WebGUI-* fields
for my $key (grep /^x-webgui-/, keys %{$events{$id}}) {
my $property_name = $key;
$property_name =~ s/^x-webgui-//;
$property_name = lc $property_name;
if ($property_name eq "groupidedit") {
$properties->{groupIdEdit} = $events{$id}->{$key}->[1];
}
elsif ($property_name eq "groupidview") {
$properties->{groupIdView} = $events{$id}->{$key}->[1];
}
elsif ($property_name eq "url") {
$properties->{url} = $events{$id}->{$key}->[1];
}
elsif ($property_name eq "menutitle") {
$properties->{menuTitle} = $events{$id}->{$key}->[1];
}
PROPERTY: foreach my $key (qw/groupIdEdit groupIdView url menuTitle timeZone/) {
my $property_name = 'x-webgui-'.lc $key;
next PROPERTY unless exists $event_properties->{$property_name};
$properties->{$key} = $event_properties->{$property_name}->[0]->value;
}
my $recur;
if ($events{$id}->{rrule}) {
$recur = _icalToRecur($session, $properties->{startDate}, $events{$id}->{rrule}->[1]);
if (exists $event_properties->{rrule}) {
$recur = _icalToRecur($session, $properties->{startDate}, $event_properties->{rrule}->[0]->value);
}
# save events for later