aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm50
-rw-r--r--perllib/FixMyStreet/App/Controller/Root.pm2
-rw-r--r--t/app/controller/index.t29
-rwxr-xr-xweb/index.cgi54
4 files changed, 93 insertions, 42 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 19b2dbaf7..4278c9bbb 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -8,6 +8,7 @@ use FixMyStreet::Map;
use List::MoreUtils qw(any);
use Encode;
use FixMyStreet::Map;
+use Utils;
=head1 NAME
@@ -32,15 +33,8 @@ If no search redirect back to the homepage.
sub around_index : Path : Args(0) {
my ( $self, $c ) = @_;
- # check for x,y requests and redirect them to lat,lon
- my $x = $c->req->param('x');
- my $y = $c->req->param('y');
- if ( $x || $y ) {
- my ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y );
- my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } );
- $c->res->redirect( $ll_uri, 301 );
- return;
- }
+ # handle old coord systems
+ $c->forward('redirect_en_or_xy');
# Check if we have a partial report
my $partial_report = $c->forward('load_partial');
@@ -72,6 +66,44 @@ sub around_index : Path : Args(0) {
$c->detach('display_location');
}
+=head2 redirect_en_or_xy
+
+ $c->forward('redirect_en_or_xy'); # does not return if there was rd
+
+Handle coord systems that are no longer in use.
+
+=cut
+
+sub redirect_en_or_xy : Private {
+ my ( $self, $c ) = @_;
+ my $req = $c->req;
+
+ # check for x,y requests and redirect them to lat,lon
+ my $x = $req->param('x');
+ my $y = $req->param('y');
+ my $e = $req->param('e');
+ my $n = $req->param('n');
+
+ # lat and lon - fill in below if we need to
+ my ( $lat, $lon );
+
+ if ( $x || $y ) {
+ ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y );
+ }
+
+ if ( $e || $n ) {
+ ( $lat, $lon ) = Utils::convert_en_to_latlon_truncated( $e, $n );
+ }
+
+ # return if nothing set
+ return unless $lat || $lon;
+
+ # create a uri and redirect to it
+ my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } );
+ $c->res->redirect( $ll_uri, 301 );
+ $c->detach;
+}
+
=head2 load_partial
my $partial_report = $c->forward('load_partial');
diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm
index 2dc770da5..3280d02b9 100644
--- a/perllib/FixMyStreet/App/Controller/Root.pm
+++ b/perllib/FixMyStreet/App/Controller/Root.pm
@@ -43,7 +43,7 @@ preserve old behaviour.
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
- my @old_param_keys = ( 'pc', 'x', 'y', 'lat', 'lon' );
+ my @old_param_keys = ( 'pc', 'x', 'y', 'e', 'n', 'lat', 'lon' );
my %old_params = ();
foreach my $key (@old_param_keys) {
diff --git a/t/app/controller/index.t b/t/app/controller/index.t
index 11c59d289..cebeaf676 100644
--- a/t/app/controller/index.t
+++ b/t/app/controller/index.t
@@ -10,6 +10,7 @@ $mech->get_ok('/');
subtest "check that the form goes to /around" => sub {
$mech->get_ok('/');
+ is $mech->uri->path, '/', "still on '/'";
# submit form
$mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } );
@@ -20,19 +21,37 @@ subtest "check that the form goes to /around" => sub {
"query passed along";
};
-subtest "check that requests with pc, x,y or lat,lon go to /around" => sub {
+subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub {
+
foreach my $test ( #
- { pc => 'SW1A 1AA' }, #
- { lat => 51.50100, lon => -0.14158 },
+ {
+ in => { pc => 'SW1A 1AA' },
+ out => { pc => 'SW1A 1AA' },
+ },
+ {
+ in => { lat => 51.50100, lon => -0.14158 },
+ out => { lat => 51.50100, lon => -0.14158 },
+ },
+ {
+ in => { x => 3281, y => 1113, },
+ out => { lat => 51.4998246332569, lon => -0.140137309739907 },
+ },
+ {
+ in => { e => 1234, n => 4567 },
+ out => { lat => 49.808509, lon => -7.544784 },
+ },
)
{
+
my $uri = URI->new('http://localhost/');
- $uri->query_form($test);
+ $uri->query_form( $test->{in} );
+
+ # get the uri and check for 302
$mech->get_ok($uri);
# check that we are at /around
is $mech->uri->path, '/around', "Got to /around";
- is_deeply { $mech->uri->query_form }, $test, "query passed along";
+ is_deeply { $mech->uri->query_form }, $test->{out}, "query correct";
}
};
diff --git a/web/index.cgi b/web/index.cgi
index 45992d7c5..0bf2ce8a0 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -105,9 +105,9 @@ sub main {
# ( $out, %params ) = display_location($q);
# $params{title} = _('Viewing a location');
# }
- elsif ( $q->param('e') && $q->param('n') ) {
- ( $out, %params ) = redirect_from_osgb_to_wgs84($q);
- }
+ # elsif ( $q->param('e') && $q->param('n') ) {
+ # ( $out, %params ) = redirect_from_osgb_to_wgs84($q);
+ # }
# else {
# ( $out, %params ) = front_page($q);
# }
@@ -830,30 +830,30 @@ sub submit_update {
# }
# redirect from osgb
-sub redirect_from_osgb_to_wgs84 {
- my ($q) = @_;
-
- my $e = $q->param('e');
- my $n = $q->param('n');
-
- my ( $lat, $lon ) = Utils::convert_en_to_latlon_truncated( $e, $n );
-
- my $lat_lon_url = NewURL(
- $q,
- -retain => 1,
- e => undef,
- n => undef,
- lat => $lat,
- lon => $lon
- );
-
- print $q->redirect(
- -location => $lat_lon_url,
- -status => 301, # permanent
- );
-
- return '';
-}
+# sub redirect_from_osgb_to_wgs84 {
+# my ($q) = @_;
+#
+# my $e = $q->param('e');
+# my $n = $q->param('n');
+#
+# my ( $lat, $lon ) = Utils::convert_en_to_latlon_truncated( $e, $n );
+#
+# my $lat_lon_url = NewURL(
+# $q,
+# -retain => 1,
+# e => undef,
+# n => undef,
+# lat => $lat,
+# lon => $lon
+# );
+#
+# print $q->redirect(
+# -location => $lat_lon_url,
+# -status => 301, # permanent
+# );
+#
+# return '';
+# }
# sub display_location {
# my ($q, @errors) = @_;