From c3652d12a9cc864ba7a2401a2cd14454816ce82f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 30 May 2011 11:34:43 -0700 Subject: [PATCH] Band-aid fix for bad decache of icalFeeds, where it is not deserialized from JSON. Fixes bug #12139. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/Calendar.pm | 8 ++++++-- t/Asset/Wobject/Calendar.t | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index c680324c8..849e51d87 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -3,6 +3,7 @@ - fixed #12142: Copy fails on imported threads - canView will now be checked before calling ANY www_ method on account plugins to fix an Inbox security bug (and other similar potential bugs). + - fixed #12139: break on calander feeds during upgrade 7.10.17 - fixed: Forced to use a PayDriver even with a balance of 0 in the cart. diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index ba8f2fed6..bc1f1ab08 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -712,7 +712,8 @@ sub getFeed { =head2 getFeeds ( ) -Gets an arrayref of hashrefs of all the feeds attached to this calendar. +Gets an arrayref of hashrefs of all the feeds attached to this calendar. Since the icalFeeds +property does double duty as JSON and Perl, deserialize from JSON if it's not already perl. TODO: Format lastUpdated into the user's time zone @@ -720,7 +721,10 @@ TODO: Format lastUpdated into the user's time zone sub getFeeds { my $self = shift; - return $self->get('icalFeeds'); + my $feeds = $self->get('icalFeeds'); + return $feeds if (ref $feeds); + $self->session->log->warn('improperly stored icalFeed in calendar assetId:'.$self->getId); + return JSON::from_json($feeds); } #---------------------------------------------------------------------------- diff --git a/t/Asset/Wobject/Calendar.t b/t/Asset/Wobject/Calendar.t index ae8aba715..30bde489f 100644 --- a/t/Asset/Wobject/Calendar.t +++ b/t/Asset/Wobject/Calendar.t @@ -57,7 +57,7 @@ use Data::Dumper; use WebGUI::Asset::Wobject::Calendar; use WebGUI::Asset::Event; -plan tests => 12 + scalar @icalWrapTests; +plan tests => 15 + scalar @icalWrapTests; my $session = WebGUI::Test->session; @@ -302,8 +302,6 @@ addToCleanup($tag2); is(scalar @{ $windowCal->getLineage(['children'])}, 17, 'added events to the window calendar'); -diag "startDate: ". $windowStart->toDatabase; -diag "endDate: ". $windowEnd->toDatabase; my @window = $windowCal->getEventsIn($windowStart->toDatabase, $windowEnd->toDatabase); cmp_bag( @@ -595,3 +593,16 @@ cmp_deeply( [], 'getFeeds: returns an empty array ref with no feeds' ); + +##Update with JSON and try again :) +$feedCal->update({icalFeeds => '[]'}); +is_deeply $feedCal->get('icalFeeds'), [], 'set as JSON, returned perl'; + +$feedCal->{_properties}->{icalFeeds} = '[]'; +is $feedCal->get('icalFeeds'), '[]', 'poked into the object directly, returned as JSON'; + +cmp_deeply( + $feedCal->getFeeds(), + [], + 'but getFeeds still returns a data structure.' +);