aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-06-07 17:11:50 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-06-07 17:11:50 +0100
commit891428159dd27e5648676b7b9b51c5a2fe2f83ed (patch)
tree1aa9862e3ab0cd981f0979ce1b29610e4b967657 /perllib/FixMyStreet
parent0f7de6563d4c96fa1ec9c429cca7e42259e25422 (diff)
Remove fake_q and most of now-unused Page.pm.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App.pm37
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm39
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm23
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm1
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm1
-rw-r--r--perllib/FixMyStreet/FakeQ.pm60
6 files changed, 41 insertions, 120 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index ec7ec3ff0..09a8609fe 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -11,7 +11,6 @@ use mySociety::Email;
use mySociety::EmailUtil;
use mySociety::Random qw(random_bytes);
use FixMyStreet::Map;
-use FixMyStreet::FakeQ;
use URI;
use URI::QueryParam;
@@ -133,11 +132,6 @@ sub _get_cobrand {
my $cobrand = $cobrand_class->new( { request => $c->req } );
- # create the cobrand explicitly passing in the site. Avoids the chicken and
- # egg situation where one needs to be created first. Should disappear when
- # all instances of the old '$q' are gone.
- $cobrand->fake_q( $c->fake_q( { site => $cobrand->moniker } ) );
-
return $cobrand;
}
@@ -390,37 +384,6 @@ sub uri_for_email {
return URI->new($email_uri);
}
-=head2 fake_q
-
- $q = $c->fake_q(); # normal usage
- $q = $c->fake_q( { site => 'cobrand_moniker' } ); # when creating
-
-Returns a faked up object that behaves as the old code expects the old '$q' to
-behave. Object is cached for the request. See L<FixMyStreet::FakeQ> for more
-details.
-
-The first time fake_q is called you need to pass in 'site' explicitly. This
-should normally be done automatically when the cobrand is first loaded.
-
-=cut
-
-sub fake_q {
- my $c = shift;
- my $args = shift;
-
- return $c->stash->{fakeq} #
- ||= $c->_get_fake_q($args);
-}
-
-sub _get_fake_q {
- my $c = shift;
- my $args = shift || {};
-
- $args->{params} ||= $c->req->parameters;
-
- return FixMyStreet::FakeQ->new($args);
-}
-
=head1 SEE ALSO
L<FixMyStreet::App::Controller::Root>, L<Catalyst>
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 3e71cb0bd..c14b7e9b1 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Geocode;
use Encode;
+use Image::Magick;
use Sort::Key qw(keysort);
use List::MoreUtils qw(uniq);
use HTML::Entities;
@@ -13,6 +14,7 @@ use mySociety::MaPit;
use Path::Class;
use Utils;
use mySociety::EmailUtil;
+use mySociety::TempFiles;
=head1 NAME
@@ -737,7 +739,7 @@ sub process_photo_upload : Private {
# convert the photo into a blob (also resize etc)
my $photo_blob =
- eval { Page::process_photo( $upload->fh, $args->{rotate_photo} ) };
+ eval { _process_photo( $upload->fh, $args->{rotate_photo} ) };
if ( my $error = $@ ) {
my $format = _(
"That image doesn't appear to have uploaded correctly (%s), please try again."
@@ -987,6 +989,41 @@ sub redirect_to_around : Private {
return $c->res->redirect($around_uri);
}
+sub _process_photo {
+ my $fh = shift;
+ my $import = shift;
+
+ my $blob = join('', <$fh>);
+ close $fh;
+ my ($handle, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
+ print $handle $blob;
+ close $handle;
+
+ my $photo = Image::Magick->new;
+ my $err = $photo->Read($filename);
+ unlink $filename;
+ throw Error::Simple("read failed: $err") if "$err";
+ $err = $photo->Scale(geometry => "250x250>");
+ throw Error::Simple("resize failed: $err") if "$err";
+ my @blobs = $photo->ImageToBlob();
+ undef $photo;
+ $photo = $blobs[0];
+ return $photo unless $import; # Only check orientation for iPhone imports at present
+
+ # Now check if it needs orientating
+ ($fh, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
+ print $fh $photo;
+ close $fh;
+ my $out = `jhead -se -autorot $filename`;
+ if ($out) {
+ open(FP, $filename) or throw Error::Simple($!);
+ $photo = join('', <FP>);
+ close FP;
+ }
+ unlink $filename;
+ return $photo;
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index a2d1bc0bb..e02b208dc 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -11,7 +11,7 @@ use mySociety::MaPit;
=head2 new
my $cobrand = $class->new;
- my $cobrand = $class->new( { request => $c->req, fake_q => $c->fake_q } );
+ my $cobrand = $class->new( { request => $c->req } );
Create a new cobrand object, optionally setting the web request.
@@ -55,27 +55,6 @@ sub is_default {
return $self->moniker eq 'default';
}
-=head2 fake_q
-
- $fake_q = $cobrand->fake_q;
- $new_fake_q = $cobrand->fake_q($new_fake_q);
-
-Often the cobrand needs access to the request so we add it at the start by
-passing it to ->new. If the request has not been set and you call this (or a
-method that needs it) then it croaks. This is probably because you are trying to
-use a request-related method out of a request-context.
-
-=cut
-
-sub fake_q {
- my $self = shift;
- $self->{fake_q} = shift if @_;
-
- return $self->{fake_q}
- || croak "No fake_q has been set"
- . " - should you be calling this method outside of a web request?";
-}
-
=head2 path_to_web_templates
$path = $cobrand->path_to_web_templates( );
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 40801306b..68175dead 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -72,6 +72,7 @@ __PACKAGE__->belongs_to(
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:71bSUgPf3uW607g2EGl/Vw
use DateTime::TimeZone;
+use Image::Size;
use Moose;
use namespace::clean -except => [ 'meta' ];
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index c3b387710..c3475e31c 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -104,6 +104,7 @@ __PACKAGE__->has_many(
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U3aYCRwE4etekKaHdhEkIw
use DateTime::TimeZone;
+use Image::Size;
use Moose;
use namespace::clean -except => [ 'meta' ];
diff --git a/perllib/FixMyStreet/FakeQ.pm b/perllib/FixMyStreet/FakeQ.pm
deleted file mode 100644
index 19f5ab32b..000000000
--- a/perllib/FixMyStreet/FakeQ.pm
+++ /dev/null
@@ -1,60 +0,0 @@
-package FixMyStreet::FakeQ;
-
-use strict;
-use warnings;
-use Carp;
-
-=head1 NAME
-
-FixMyStreet::FakeQ - adaptor object to ease code transition
-
-=head1 DESCRIPTION
-
-The old code uses '$q' everywhere - partly to passaround which cobrand is in
-use, partly to give access to the request query parameters and partly as a
-scratch pad.
-
-This object lets us fake this behaviour in a structured way so that the new
-Catalyst based code can call the old CGI code with no need for changes.
-
-Eventually it will be phased out.
-
-=head1 METHODS
-
-=head2 new
-
- $fake_q = FixMyStreet::FakeQ->new( $args );
-
-Create a new FakeQ object. Checks that 'site' argument is present and corrects
-it if needed.
-
-=cut
-
-sub new {
- my $class = shift;
- my $args = shift || {};
-
- croak "required argument 'site' missing" unless $args->{site};
- $args->{site} = 'fixmystreet' if $args->{site} eq 'default';
-
- $args->{params} ||= {};
-
- return bless $args, $class;
-}
-
-=head2 param
-
- $val = $fake_q->param( 'key' );
-
-Behaves much like CGI's ->param. Returns value if found, or undef if not.
-
-=cut
-
-sub param {
- my $self = shift;
- my $key = shift;
-
- return $self->{params}->{$key};
-}
-
-1;