diff options
-rwxr-xr-x | bin/rotate-photos | 34 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 1 | ||||
-rw-r--r-- | perllib/Utils.pm | 18 | ||||
-rw-r--r-- | t/app/controller/around.t | 5 |
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 { |