Do not append ;adminId to the URL stored for calendar feeds. Add upgrade code to fixing existing, broken feeds. Fixes bug #12164

This commit is contained in:
Colin Kuskie 2011-06-27 14:40:46 -07:00
parent 97ec859653
commit f728b22843
5 changed files with 66 additions and 11 deletions

View file

@ -2,6 +2,7 @@
- fixed #12169: extras uploads symlink export
- Added ability to pass caller assetId to RenderThingMacro
- Allow specific expirations for groups in userImport.pl
- fixed #12164: Calendar feeds with tons of ;adminId=XXXXXX added
7.10.18
- fixed #12138: Version tag gets create by entering and direct leaving

View file

@ -22,6 +22,8 @@ use Getopt::Long;
use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::Asset;
use WebGUI::Asset::Wobject::Calendar;
use Exception::Class;
my $toVersion = '7.10.19';
@ -32,6 +34,7 @@ my $session = start(); # this line required
# upgrade functions go here
addTicketLimitToBadgeGroup( $session );
fixBrokenCalendarFeedUrls ( $session );
finish($session); # this line required
@ -45,6 +48,25 @@ finish($session); # this line required
# print "DONE!\n" unless $quiet;
#}
#----------------------------------------------------------------------------
# Fix calendar feed urls that had adminId attached to them until they blew up
sub fixBrokenCalendarFeedUrls {
my $session = shift;
print "\tChecking all calendar feed URLs for adminId brokenness... " unless $quiet;
my $getCalendar = WebGUI::Asset::Wobject::Calendar->getIsa($session);
CALENDAR: while (1) {
my $calendar = eval { $getCalendar->(); };
next CALENDAR if Exception::Class->caught;
last CALENDAR unless $calendar;
FEED: foreach my $feed (@{ $calendar->getFeeds }) {
$feed->{url} =~ s/adminId=[^;]{22};?//g;
$feed->{url} =~ s/\?$//;
$calendar->setFeed($feed->{feedId}, $feed);
}
}
print "DONE!\n" unless $quiet;
}
#----------------------------------------------------------------------------
# Add a ticket limit to badges in a badge group
sub addTicketLimitToBadgeGroup {

View file

@ -120,22 +120,23 @@ sub execute {
# and send the appropriate cookie with the request.
my $sitename = $session->config->get("sitename")->[0];
FEED: foreach my $feed (@{ $calendar->getFeeds }) {
if ($feed->{url} =~ m{http://[^/]*$sitename}) {
$feed->{url} .= ( $feed->{url} =~ /[?]/ ? ";" : "?" ) . "adminId=".$session->getId;
my $url = $feed->{url};
if ($url =~ m{http://[^/]*$sitename}) {
$url .= ( $url =~ /[?]/ ? ";" : "?" ) . "adminId=".$session->getId;
$session->db->write("REPLACE INTO userSessionScratch (sessionId,name,value) VALUES (?,?,?)",
[$session->getId,$calendar->getId,"SPECTRE"]);
}
# Get the feed
$session->log->info( "Trying Calendar feed ".$feed->{url}." for $calendarTitle" );
my $response = $ua->get($feed->{url});
$session->log->info( "Trying Calendar feed ".$url." for $calendarTitle" );
my $response = $ua->get($url);
if (!$response->is_success) {
# Update the result and last updated fields
$feed->{lastResult} = $response->message || $response->content;
$feed->{lastUpdated} = $dt;
$calendar->setFeed($feed->{feedId}, $feed);
$session->log->info( "Calendar feed ".$feed->{url}." for $calendarTitle failed" );
$session->log->warn( "Calendar feed ".$url." for $calendarTitle failed" );
next FEED;
}
@ -146,7 +147,8 @@ sub execute {
$feed->{lastResult} = "Error parsing iCal feed";
$feed->{lastUpdated} = $dt;
$calendar->setFeed($feed->{feedId}, $feed);
#next FEED;
$session->log->warn( "Calendar feed ".$url." for $calendarTitle could not be parsed" );
next FEED;
}
my $feedData = $feedList->{$feed->{feedId}} = {
added => 0,

View file

@ -15,7 +15,6 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use Test::More; # increment this value for each test you create
use Test::Deep;
plan tests => 30;
use WebGUI::Session;

View file

@ -16,17 +16,16 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Utility;
use WebGUI::Workflow::Activity::CalendarUpdateFeeds;
use WebGUI::Asset::Wobject::Calendar;
use Test::More;
use Test::Deep;
use Test::LongString;
use Data::Dumper;
use WebGUI::Asset::Wobject::Calendar;
plan skip_all => 'set WEBGUI_LIVE to enable this test'
unless $ENV{WEBGUI_LIVE};
plan tests => 23; # increment this value for each test you create
plan tests => 27; # increment this value for each test you create
my $session = WebGUI::Test->session;
@ -176,7 +175,7 @@ SKIP: {
##Add an ical feed to check time zone processing
$receiver->deleteFeed($feedId);
$receiver->addFeed({
$feedId = $receiver->addFeed({
url => $session->url->getSiteURL.$snippet_feed->getUrl,
lastUpdated => 'never',
});
@ -204,4 +203,36 @@ $newEvents = $receiver->getLineage(['children'], { returnObjects => 1, });
my $got_cpr = is(scalar @{ $newEvents }, 1, 'ical import of 1 event');
##Add a feed that will fail, to test that feeds are not modified
$receiver->deleteFeed($feedId);
my $feedUrl = $session->url->getSiteURL.'do_not_hack_my_url';
$feedId = $receiver->addFeed({
url => $feedUrl,
lastUpdated => 'never',
});
$instance1->delete('skipNotify');
$instance1 = WebGUI::Workflow::Instance->create($session,
{
workflowId => $workflow->getId,
skipSpectreNotification => 1,
}
);
my $retVal;
$retVal = $instance1->run();
is($retVal, 'complete', 'cleanup: activity complete');
$retVal = $instance1->run();
is($retVal, 'done', 'cleanup: activity is done');
$instance1->delete;
$receiver = $receiver->cloneFromDb;
my $feed = $receiver->getFeed($feedId);
##Note, cannot use Test::Deep in here because Asset/Event.pm use Test::Deep::NoTest
is $feed->{lastResult}, 'Error parsing iCal feed', 'After fetching a bad feed it updated the lastResult';
is $feed->{url}, $feedUrl, '... nothing added to feed URL';
#vim:ft=perl