]> git.sesse.net Git - pr0n/blobdiff - perl/update-image-info.pl
Support a new form of image: box/, which is exactly the opposite of nobox/
[pr0n] / perl / update-image-info.pl
index 41d823723c858f530750ebc055cc9b65acc45fda..611a4b51cb65b9da99d926d1dea3d19baba4b93d 100755 (executable)
@@ -1,4 +1,9 @@
 #! /usr/bin/perl
+
+# Warning: This is sort of outdated now. :-/ What really should be done is make
+#          update_image_info() includeable from outside mod_perl, so we don't have
+#          to duplicate the code in here.
+
 use lib qw(.);
 use DBI;
 use POSIX;
@@ -36,28 +41,32 @@ while (my $ref = $q->fetchrow_hashref) {
                }
        }
 
-       $dbh->do('UPDATE images SET width=?, height=?, date=? WHERE id=?',
-                undef, $width, $height, $datetime, $id)
-               or die "Couldn't update width/height in SQL: $!";
+       {
+               local $dbh->{AutoCommit} = 0;
 
-       $dbh->do('DELETE FROM exif_info WHERE image=?',
-               undef, $id)
-               or die "Couldn't delete old EXIF information in SQL: $!";
+               $dbh->do('UPDATE images SET width=?, height=?, date=? WHERE id=?',
+                        undef, $width, $height, $datetime, $id)
+                       or die "Couldn't update width/height in SQL: $!";
 
-       my $q = $dbh->prepare('INSERT INTO exif_info (image,tag,value) VALUES (?,?,?)')
-               or die "Couldn't prepare inserting EXIF information: $!";
+               $dbh->do('DELETE FROM exif_info WHERE image=?',
+                       undef, $id)
+                       or die "Couldn't delete old EXIF information in SQL: $!";
 
-       for my $key (keys %$info) {
-               next if ref $info->{$key};
-               $q->execute($id, $key, guess_charset($info->{$key}))
-                       or die "Couldn't insert EXIF information in database: $!";
-       }
+               my $q = $dbh->prepare('INSERT INTO exif_info (image,tag,value) VALUES (?,?,?)')
+                       or die "Couldn't prepare inserting EXIF information: $!";
 
-       # update the last_picture cache as well (this should of course be done
-       # via a trigger, but this is less complicated :-) )
-       $dbh->do('UPDATE last_picture_cache SET last_picture=GREATEST(last_picture, ?) WHERE event=(SELECT event FROM images WHERE id=?)',
-               undef, $datetime, $id)
-               or die "Couldn't update last_picture in SQL: $!";
+               for my $key (keys %$info) {
+                       next if ref $info->{$key};
+                       $q->execute($id, $key, guess_charset($info->{$key}))
+                               or die "Couldn't insert EXIF information in database: $!";
+               }
+
+               # update the last_picture cache as well (this should of course be done
+               # via a trigger, but this is less complicated :-) )
+               $dbh->do('UPDATE last_picture_cache SET last_picture=GREATEST(last_picture, ?) WHERE event=(SELECT event FROM images WHERE id=?)',
+                       undef, $datetime, $id)
+                       or die "Couldn't update last_picture in SQL: $!";
+       }
 
        print "Updated $id.\n";
 }