From 9d23030bc3cfc114729e86c6ad23190f54f65d76 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Mon, 1 Aug 2011 19:24:40 +0200 Subject: Try to get Open311 GeoRSS output working. --- perllib/FixMyStreet/App/Controller/Rss.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Rss.pm') diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 78793d9c1..4a5b320ed 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -191,13 +191,16 @@ sub query_main : Private { my ( $site_restriction, $site_id ) = $c->cobrand->site_restriction( $c->cobrand->extra_data ); # Only apply a site restriction if the alert uses the problem table $site_restriction = '' unless $alert_type->item_table eq 'problem'; + my $search_criteria = $c->stash->{search_criteria}; # FIXME Do this in a nicer way at some point in the future... my $query = 'select * from ' . $alert_type->item_table . ' where ' . ($alert_type->head_table ? $alert_type->head_table . '_id=? and ' : '') - . $alert_type->item_where . $site_restriction . ' order by ' - . $alert_type->item_order; + . $alert_type->item_where . $site_restriction . + . ($search_criteria ? "and $search_criteria" : '') + . ' order by ' . $alert_type->item_order; my $rss_limit = mySociety::Config::get('RSS_LIMIT'); + $rss_limit = $c->stash->{max_requests} if $c->stash->{max_requests}; $query .= " limit $rss_limit" unless $c->stash->{type} =~ /^all/; my $q = $c->model('DB::Alert')->result_source->storage->dbh->prepare($query); -- cgit v1.2.3 From 14ec45fe5b09ca46f30968ca4f173e909cabdec7 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Tue, 2 Aug 2011 00:12:22 +0200 Subject: Try different approachh. --- perllib/FixMyStreet/App/Controller/Rss.pm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Rss.pm') diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 4a5b320ed..640c0bb47 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -156,7 +156,8 @@ sub output : Private { $c->detach( '/page_error_404_not_found', [ _('Unknown alert type') ] ) unless $c->stash->{alert_type}; - $c->forward( 'query_main' ); + my $query_func = $c->stash->{query_func} || 'query_main'; + $c->forward( $query_func ); # Do our own encoding $c->stash->{rss} = new XML::RSS( @@ -191,16 +192,13 @@ sub query_main : Private { my ( $site_restriction, $site_id ) = $c->cobrand->site_restriction( $c->cobrand->extra_data ); # Only apply a site restriction if the alert uses the problem table $site_restriction = '' unless $alert_type->item_table eq 'problem'; - my $search_criteria = $c->stash->{search_criteria}; # FIXME Do this in a nicer way at some point in the future... my $query = 'select * from ' . $alert_type->item_table . ' where ' . ($alert_type->head_table ? $alert_type->head_table . '_id=? and ' : '') - . $alert_type->item_where . $site_restriction . - . ($search_criteria ? "and $search_criteria" : '') - . ' order by ' . $alert_type->item_order; + . $alert_type->item_where . $site_restriction . ' order by ' + . $alert_type->item_order; my $rss_limit = mySociety::Config::get('RSS_LIMIT'); - $rss_limit = $c->stash->{max_requests} if $c->stash->{max_requests}; $query .= " limit $rss_limit" unless $c->stash->{type} =~ /^all/; my $q = $c->model('DB::Alert')->result_source->storage->dbh->prepare($query); -- cgit v1.2.3 From 2c70a5164318a7b186b6cb827cc0b68c39175e1a Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 4 Aug 2011 17:20:12 +0100 Subject: Get Open311 RSS working, whether it's given a ResultSet or a lower level statement handle. --- perllib/FixMyStreet/App/Controller/Rss.pm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Rss.pm') diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 640c0bb47..45a16a9dd 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -151,13 +151,21 @@ sub local_problems_ll : Private { sub output : Private { my ( $self, $c ) = @_; + $c->forward( 'lookup_type' ); + $c->forward( 'query_main' ); + $c->forward( 'generate' ); +} + +sub lookup_type : Private { + my ( $self, $c ) = @_; $c->stash->{alert_type} = $c->model('DB::AlertType')->find( { ref => $c->stash->{type} } ); $c->detach( '/page_error_404_not_found', [ _('Unknown alert type') ] ) unless $c->stash->{alert_type}; +} - my $query_func = $c->stash->{query_func} || 'query_main'; - $c->forward( $query_func ); +sub generate : Private { + my ( $self, $c ) = @_; # Do our own encoding $c->stash->{rss} = new XML::RSS( @@ -171,8 +179,15 @@ sub output : Private { uri => 'http://www.georss.org/georss' ); - while (my $row = $c->stash->{query_main}->fetchrow_hashref) { - $c->forward( 'add_row', [ $row ] ); + my $problems = $c->stash->{problems}; + if ( $problems->can('fetchrow_hashref') ) { + while ( my $row = $problems->fetchrow_hashref ) { + $c->forward( 'add_row', [ $row ] ); + } + } else { + while ( my $row = $problems->next ) { + $c->forward( 'add_row', [ $row ] ); + } } $c->forward( 'add_parameters' ); @@ -211,7 +226,7 @@ sub query_main : Private { } else { $q->execute(); } - $c->stash->{query_main} = $q; + $c->stash->{problems} = $q; } sub add_row : Private { -- cgit v1.2.3