Fix iCal processing in the Calendar module and workflow. Errors with

generation and processing.
This commit is contained in:
Colin Kuskie 2009-06-30 15:43:40 +00:00
parent bb3de4bf96
commit 755d7909a5
4 changed files with 153 additions and 33 deletions

View file

@ -671,11 +671,22 @@ TODO: Allow WebGUI::DateTime objects to be passed as the parameters.
This is the main API method to get events from a calendar, so it must be flexible.
C<options> is a hash reference with the following keys:
=head3 startDate
order - The order to return the events. Will default to the
sortEventsBy asset property. Valid values are:
'time', 'sequenceNumber'
A date with optional time in MySQL format.
=head3 endDate
A date with optional time in MySQL format.
=head3 options
A hash reference with any the following keys and values:
=head4 order
The order to return the events. Will default to the sortEventsBy asset property.
Valid values are: 'time', 'sequenceNumber'
=cut
@ -698,21 +709,23 @@ sub getEventsIn {
# Create objects and adjust for timezone
warn "start: $start\n";
warn "end: $end\n";
my ($startDate,$startTime) = split / /, $start;
my ($endDate,$endTime) = split / /, $end;
#use Data::Dumper;
#$self->session->errorHandler->warn( Dumper [caller(1), caller(2), caller(3)] );
my $startTz = WebGUI::DateTime->new($self->session, mysql => $start, time_zone => $tz)
->set_time_zone("UTC")->toMysql;
my $endTz = WebGUI::DateTime->new($self->session, mysql => $end, time_zone => $tz)
->set_time_zone("UTC")->toMysql;
my $startTz = WebGUI::DateTime->new($self->session, mysql => $start, time_zone => $tz)->set_time_zone("UTC")->toMysql;
my $endTz = WebGUI::DateTime->new($self->session, mysql => $end, time_zone => $tz)->set_time_zone("UTC")->toMysql;
warn $startTz;
warn $endTz;
my $where
= qq{
(
Event.startTime IS NULL
&& Event.endTime IS NULL
Event.startTime IS NULL
&& Event.endTime IS NULL
&&
!(
Event.startDate >= '$endDate'
@ -720,7 +733,7 @@ sub getEventsIn {
)
)
|| (
CONCAT(Event.startDate,' ',Event.startTime) >= '$startTz'
CONCAT(Event.startDate,' ',Event.startTime) >= '$startTz'
&& CONCAT(Event.startDate,' ',Event.startTime) < '$endTz'
)
};
@ -1738,7 +1751,7 @@ sub wrapIcal {
$text =~ s/([,;\\])/\\$1/g;
$text =~ s/\n/\\n/g;
my @text = ($text =~ m/.{0,75}/g);
my @text = ($text =~ m/.{1,75}/g);
return join "\r\n ",@text;
}

View file

@ -121,7 +121,6 @@ sub execute {
[$session->getId,$feed->{assetId},"SPECTRE"]);
}
#/KLUDGE
#warn "FEED URL: ".$feed->{url} ."\n";
## Somebody point me to a DECENT iCalendar parser...
# Text::vFile perhaps?
@ -148,10 +147,10 @@ sub execute {
my $active = 0; # Parser on/off
my %current_event = ();
my $current_entry = "";
my %events;
my $line_number = 0;
for my $line (split /[\r\n]+/,$data) {
$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/;
@ -160,6 +159,7 @@ sub execute {
if ($line =~ /^BEGIN:VEVENT$/i) {
$active = 1;
next LINE;
}
elsif ($line =~ /^END:VEVENT$/i) {
$active = 0;
@ -169,15 +169,12 @@ sub execute {
$events{$uid} = {%current_event};
$self->session->log->info( "Found event $uid from feed " . $feed->{feedId} );
%current_event = ();
}
elsif ($line =~ /^ /) {
# Add to entry data
$current_entry .= substr $line, 1;
next LINE;
}
else {
# Flush old entry
# KEY;ATTRIBUTE=VALUE;ATTRIBUTE=VALUE:KEYVALUE
my ($key_attrs,$value) = split /:/,$current_entry,2;
my ($key_attrs,$value) = split /:/,$line,2;
my @attrs = $key_attrs ? (split /;/, $key_attrs) : ();
my $key = shift @attrs;
my %attrs;
@ -186,13 +183,7 @@ sub execute {
$attrs{lc $attr_key} = $attr_value;
}
# Unescape value
$current_event{lc $key} = [\%attrs,$value];
# Start new entry
$current_entry = $line;
}
}
@ -330,23 +321,24 @@ sub execute {
}
# If there are X-WebGUI-* fields
for my $key (grep /^X-WEBGUI-/, keys %{$events{$id}}) {
for my $key (grep /^x-webgui-/, keys %{$events{$id}}) {
my $property_name = $key;
$property_name =~ s/^X-WEBGUI-//;
$property_name =~ s/^x-webgui-//;
$property_name = lc $property_name;
if (lc $property_name eq "groupidedit")
if ($property_name eq "groupidedit")
{
$properties->{groupIdEdit} = $events{$id}->{$key}->[1];
}
elsif (lc $property_name eq "groupidview")
elsif ($property_name eq "groupidview")
{
$properties->{groupIdView} = $events{$id}->{$key}->[1];
}
elsif (lc $property_name eq "url")
elsif ($property_name eq "url")
{
$properties->{url} = $events{$id}->{$key}->[1];
}
elsif (lc $property_name eq "menutitle")
elsif ($property_name eq "menutitle")
{
$properties->{menuTitle} = $events{$id}->{$key}->[1];
}
@ -538,7 +530,7 @@ sub _icalToMySQL {
sub _unwrapIcalText {
my $text = shift;
$text =~ s/\\([.;\\])/$1/g;
$text =~ s/\\([,;\\])/$1/g;
return $text;
}