Subject: | Net::CalDAVTalk->UpdateEvent() does not copy the event values |
Due to what I guess is a refactoring, the properties of the old event do not get copied into the new, merged event anymore when calling ->_updateEvent(), which is called ->UpdateEvent(). This makes updating events using Net::CalDAVTalk hard.
The attached test reproduces the problem.
The fix is to change
ub _updateEvent {
my ($Self, $href, $Args) = @_;
my $OldEvent = $Self->GetEvent($href);
confess "Error getting old event for $href"
unless $OldEvent;
my %NewEvent;
- foreach my $Property (keys %EventKeys) {
+ foreach my $Property (keys %{$EventKeys{''}}) {
if (exists $Args->{$Property}) {
if (defined $Args->{$Property}) {
$NewEvent{$Property} = $Args->{$Property};
}
}
elsif (exists $OldEvent->{$Property}) {
$NewEvent{$Property} = $OldEvent->{$Property};
}
}
# calculate updated sequence numbers
unless (exists $Args->{sequence}) {
$NewEvent{sequence} = ($OldEvent->{sequence} || 0) + 1;
}
Subject: | net-caldavtalk-updateevent.t |
#!perl
use strict;
use warnings;
use Net::CalDAVTalk;
use Test::More tests => 1;
my $merged_result = {
'sequence' => 1,
'href' => '/myuid',
'uid' => '2DDB4067-42FF-xxxx-xxxx-xxxxxxxx',
'duration' => 'PT14H25M',
'prodId' => '-//NP4GmbH//PCSOffice//EN',
'title' => 'title',
'start' => '2020-01-01T16:40:00',
'locations' => {
'location' => {
'name' => 'Here (old)'
}
},
'timeZone' => 'Etc/UTC',
'updated' => '2019-09-24T07:10:12Z',
'created' => '2019-09-24T07:10:12Z',
'isAllDay' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'description' => 'Random new description'
};
my $old = { %$merged_result };
$old->{description} = 'Random old description';
# Fake data so we don't need a network connection or a real server
sub Net::CalDAVTalk::GetEvent {
my( $self, $href ) = @_;
die "Mock sub called for wrong value '$href'"
unless $href eq '/myuid';
return $old;
};
my $event = { %$merged_result };
$event->{locations}->{location} = 'There (new)';
my $caldav = bless {}, 'Net::CalDAVTalk';
my $new_event = $caldav->_updateEvent('/myuid', $event);
is_deeply $new_event, $merged_result;