diff options
author | Struan Donald <struan@exo.org.uk> | 2011-09-09 19:24:09 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-09-09 19:24:09 +0100 |
commit | d1020f6d455aa729ca52d18ccb39d531a866f4fc (patch) | |
tree | a9a02c62afc20b54d8f934766b9515050de02606 /perllib/FixMyStreet | |
parent | 63e03938cbc9401eccf36bdce8f312f171559c80 (diff) |
sort of working rss address stuff with db caching and populate script
Diffstat (limited to 'perllib/FixMyStreet')
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 39 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 28 |
3 files changed, 58 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 767d38c21..c2a0eee7e 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -265,8 +265,9 @@ sub add_row : Private { } if ( $row->{used_map} ) { - #my $address = $c->cobrand->find_closest_address_for_rss( $row->{latitude}, $row->{longitude} ); - #$item{description} .= ent("\n<br>$address"); + # TODO: uncomment these when the populate script has been run + # my $address = $c->cobrand->find_closest_address_for_rss( $row->{latitude}, $row->{longitude}, $row ); + # $item{description} .= ent("\n<br>$address"); } my $recipient_name = $c->cobrand->contact_name; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 1e87468ac..e1bf196bd 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -576,18 +576,37 @@ Used by rss feeds to provide a bit more context =cut sub find_closest_address_for_rss { - my ( $self, $latitude, $longitude ) = @_; + my ( $self, $latitude, $longitude, $problem ) = @_; my $str = ''; - if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ) ) { - if ($j->{resourceSets}[0]{resources}[0]{name}) { - my $address = $j->{resourceSets}[0]{resources}[0]{address}; - my @address; - push @address, $address->{addressLine} if $address->{addressLine} ne 'Street'; - push @address, $address->{locality}; - $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), - join( ', ', @address ) ); - } + my $j; + if ( $problem && ref($problem) =~ /FixMyStreet/ && $problem->can( 'geocode' ) ) { + $j = $problem->geocode; + } else { + $problem = FixMyStreet::App->model('DB::Problem')->find( { id => $problem->{id} } ); + $j = $problem->geocode; + } + + # if we've not cached it then we don't want to look it up in order to avoid + # hammering the bing api + # if ( !$j ) { + # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ); + + # # FIXME: work out why this does not work - see populate bing script for details + # # bad data here + # $j->{copyright} = ''; + + # $problem->geocode( $j ); + # $problem->update; + # } + + if ($j && $j->{resourceSets}[0]{resources}[0]{name}) { + my $address = $j->{resourceSets}[0]{resources}[0]{address}; + my @address; + push @address, $address->{addressLine} if $address->{addressLine} ne 'Street'; + push @address, $address->{locality}; + $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), + join( ', ', @address ) ); } return $str; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 987c92c64..8d8665258 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -78,8 +78,12 @@ __PACKAGE__->add_columns( { data_type => "timestamp", is_nullable => 1 }, "send_questionnaire", { data_type => "boolean", default_value => \"true", is_nullable => 0 }, + "extra", + { data_type => "text", is_nullable => 1 }, "flagged", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "geocode", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -102,8 +106,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3sw/1dqxlTvcWEI/eJTm4w +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-09-09 10:22:40 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:T+EtKT6/8cqMXmd/WzY4CA # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -113,6 +117,26 @@ __PACKAGE__->has_one( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->filter_column( + geocode => { + filter_from_storage => sub { + my $self = shift; + my $ser = shift; + return undef unless defined $ser; + my $h = new IO::String($ser); + return RABX::wire_rd($h); + }, + filter_to_storage => sub { + my $self = shift; + my $data = shift; + my $ser = ''; + my $h = new IO::String($ser); + RABX::wire_wr( $data, $h ); + return $ser; + }, + } +); + use DateTime::TimeZone; use Image::Size; use Moose; |