aboutsummaryrefslogtreecommitdiffstats
path: root/bin/rotate-photos
diff options
context:
space:
mode:
authorDave Whiteland <dave@mysociety.org>2012-11-14 07:59:00 +0000
committerDave Whiteland <dave@mysociety.org>2012-11-14 07:59:00 +0000
commitccd8a2e06ab90202e0205cad3b0fb8ff9ed4b78e (patch)
tree20809adc5c8365e756e17de7bd5cbafb25a00121 /bin/rotate-photos
parenta82dc396d424a33f112d54874c9c643a0d2fddcf (diff)
parent63ad6d84fdeeb2fc8f2f1af2a3f26152d5dd4423 (diff)
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet
Diffstat (limited to 'bin/rotate-photos')
-rwxr-xr-xbin/rotate-photos34
1 files changed, 23 insertions, 11 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;
}