aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-11-12 18:32:06 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-11-12 18:32:06 +0000
commit88942202e6e74c8586074ac7b7ed2d1e6f1c9a9a (patch)
tree10df3a9ec99773397faddbcf7923a46d8efac7c5
parent74c1a09a10d606d9d8850f7fb70b6e578d2c3877 (diff)
Remove unused function, add gridref test.
-rwxr-xr-xbin/rotate-photos34
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm1
-rw-r--r--perllib/Utils.pm18
-rw-r--r--t/app/controller/around.t5
4 files changed, 28 insertions, 30 deletions
diff --git a/bin/rotate-photos b/bin/rotate-photos
index faf2748e6..31a60ff6c 100755
--- a/bin/rotate-photos
+++ b/bin/rotate-photos
@@ -16,6 +16,8 @@ use FindBin;
use lib "$FindBin::Bin/../perllib";
use lib "$FindBin::Bin/../commonlib/perllib";
+use Digest::SHA1 qw(sha1_hex);
+
use Utils;
use mySociety::Config;
use mySociety::DBHandle qw(dbh select_all);
@@ -36,17 +38,27 @@ my $r = select_all("select id, photo from problem where service='iPhone'");
foreach (@$r) {
my $id = $_->{id};
my $photo = $_->{photo};
- my ($fh, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
- print $fh $photo;
- close $fh;
- my $out = `jhead -autorot $filename`;
- if ($out) {
- open(FP, $filename) or die $!;
- $photo = join('', <FP>);
- close FP;
- Utils::workaround_pg_bytea("update problem set photo=? where id=?", 1, $photo, $id);
- dbh()->commit();
+
+ if (length($photo) == 40) {
+ # If photo field contains a hash
+ my $filename = mySociety::Config::get('UPLOAD_DIR') . "$photo.jpeg";
+ `jhead -autorot $filename`;
+ } else {
+ my ($fh, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
+ print $fh $photo;
+ close $fh;
+ my $out = `jhead -autorot $filename`;
+ if ($out) {
+ open(FP, $filename) or die $!;
+ $photo = join('', <FP>);
+ close FP;
+ my $fileid = sha1_hex($photo);
+ rename $filename, mySociety::Config::get('UPLOAD_DIR') . "$fileid.jpeg";
+ dbh()->do('UPDATE problem SET photo=? WHERE id=?', {}, $fileid, $id);
+ dbh()->commit();
+ } else {
+ unlink $filename;
+ }
}
- unlink $filename;
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 3247ad0a1..09149ae14 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -13,7 +13,6 @@ use mySociety::MaPit;
use Path::Class;
use Utils;
use mySociety::EmailUtil;
-use mySociety::TempFiles;
use JSON;
=head1 NAME
diff --git a/perllib/Utils.pm b/perllib/Utils.pm
index ab7bc6e12..fa90620a0 100644
--- a/perllib/Utils.pm
+++ b/perllib/Utils.pm
@@ -19,24 +19,6 @@ use mySociety::DBHandle qw(dbh);
use mySociety::GeoUtil;
use mySociety::Locale;
-sub workaround_pg_bytea {
- my ( $st, $img_idx, @elements ) = @_;
- my $s = dbh()->prepare($st);
- for ( my $i = 1 ; $i <= @elements ; $i++ ) {
- if ( $i == $img_idx ) {
- $s->bind_param(
- $i,
- $elements[ $i - 1 ],
- { pg_type => DBD::Pg::PG_BYTEA }
- );
- }
- else {
- $s->bind_param( $i, $elements[ $i - 1 ] );
- }
- }
- $s->execute();
-}
-
=head2 convert_latlon_to_en
( $easting, $northing ) = Utils::convert_en_to_latlon( $latitude, $longitude );
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index e1c76ff9f..d973543ce 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -66,6 +66,11 @@ foreach my $test (
latitude => '51.50101',
longitude => '-0.141587',
},
+ {
+ pc => 'TQ 388 773',
+ latitude => '51.478074',
+ longitude => '-0.001966',
+ },
)
{
subtest "check lat/lng for '$test->{pc}'" => sub {