X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FRotate.pm;h=71102eb1336e5c8960e3492d248065f6b4557b41;hp=5a3fe868efc9df2325f35361befcb1eee5efdfbc;hb=dc3ef05d90b1383b3dcc6b30720b614d1b160d07;hpb=1a9cbb3a4dd482391f3a3d9f36d4f8ab3282fe58 diff --git a/perl/Sesse/pr0n/Rotate.pm b/perl/Sesse/pr0n/Rotate.pm index 5a3fe86..71102eb 100644 --- a/perl/Sesse/pr0n/Rotate.pm +++ b/perl/Sesse/pr0n/Rotate.pm @@ -14,20 +14,27 @@ sub handler { return Apache2::Const::OK; } + # FIXME: People can rotate and delete across vhosts using this interface. + # We should add some sanity checks. + + my @to_purge = (); + Sesse::pr0n::Common::header($r, "Rotation/deletion results"); { # Enable transactions and error raising temporarily - local $dbh->{AutoCommit} = 0; local $dbh->{RaiseError} = 1; my @params = $apr->param(); my $key; for $key (@params) { + local $dbh->{AutoCommit} = 0; + # Rotation if ($key =~ /^rot-(\d+)-(90|180|270)$/ && $apr->param($key) eq 'on') { my ($id, $rotval) = ($1,$2); my $fname = Sesse::pr0n::Common::get_disk_location($r, $id); + push @to_purge, Sesse::pr0n::Common::get_all_cache_urls($r, $dbh, $id); (my $tmpfname = $fname) =~ s/\.jpg$/-tmp.jpg/; system("/usr/bin/jpegtran -rotate $rotval -copy all < '$fname' > '$tmpfname' && mv '$tmpfname' '$fname'") == 0 @@ -36,22 +43,25 @@ sub handler { if ($rotval == 90 || $rotval == 270) { my $q = $dbh->do('UPDATE images SET height=width,width=height WHERE id=?', undef, $id) - or dberror($r, "Size clear of $id failed: $!"); - $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE event=( SELECT event FROM images WHERE id=? )', + or dberror($r, "Size clear of $id failed"); + $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE (vhost,event)=( SELECT vhost,event FROM images WHERE id=? )', undef, $id) or dberror($r, "Cache invalidation at $id failed"); } } elsif ($key =~ /^del-(\d+)$/ && $apr->param($key) eq 'on') { my $id = $1; + push @to_purge, Sesse::pr0n::Common::get_all_cache_urls($r, $dbh, $id); { eval { - $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE event=( SELECT event FROM images WHERE id=? )', + $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE (vhost,event)=( SELECT vhost,event FROM images WHERE id=? )', undef, $id); $dbh->do('INSERT INTO deleted_images SELECT * FROM images WHERE id=?', - undef, $id); + undef, $id); + $dbh->do('DELETE FROM exif_info WHERE image=?', + undef, $id); $dbh->do('DELETE FROM images WHERE id=?', - undef, $id); + undef, $id); }; if ($@) { # Some error occurred, rollback and bomb out @@ -63,6 +73,14 @@ sub handler { } } } + + my $event = $apr->param('event'); + $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?', undef, $r->get_server_name, $event) + or dberror($r, "Cache invalidation failed"); + + push @to_purge, "/$event/"; + push @to_purge, "/+all/"; + Sesse::pr0n::Common::purge_cache($r, @to_purge); Sesse::pr0n::Common::footer($r);