aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-05-18 11:52:30 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-05-18 11:52:30 +0100
commit66d93ceaed9df6ff3e0e28a62e655ad769c99614 (patch)
treef1942a5ffc598106e74fc38b44aee960ca28a6a9
parent5154fa740d3eca75534bd1be7a40f07342419fb7 (diff)
parentf19221e0cd17d02159c01a6ddc2c55b28ce4d730 (diff)
Merge branch '1400-remove-glob'
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm2
-rw-r--r--perllib/FixMyStreet/App/Model/PhotoSet.pm23
3 files changed, 21 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 3e757f227..db9545830 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -784,7 +784,7 @@ sub report_edit : Path('report_edit') : Args(1) {
}
if ( $remove_photo_param || $new_state eq 'hidden' ) {
- unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' );
+ $problem->get_photoset->delete_cached;
}
if ( $problem->is_visible() and $old_state eq 'unconfirmed' ) {
@@ -1005,7 +1005,7 @@ sub update_edit : Path('update_edit') : Args(1) {
}
if ( $remove_photo_param || $new_state eq 'hidden' ) {
- unlink glob FixMyStreet->path_to( 'web', 'photo', 'c', $update->id . '.*' );
+ $update->get_photoset->delete_cached;
}
$update->name( $c->get_param('name') || '' );
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index d24d3ff71..2734491fa 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -43,7 +43,7 @@ sub during :LocalRegex('^(temp|fulltemp)\.([0-9a-f]{40}\.(?:jpeg|png|gif|tiff))$
$c->forward( 'output', [ $photo ] );
}
-sub index :LocalRegex('^(c/)?(\d+)(?:\.(\d+))?(?:\.(full|tn|fp))?\.(?:jpeg|png|gif|tiff)$') {
+sub index :LocalRegex('^(c/)?([1-9]\d*)(?:\.(\d+))?(?:\.(full|tn|fp))?\.(?:jpeg|png|gif|tiff)$') {
my ( $self, $c ) = @_;
my ( $is_update, $id, $photo_number, $size ) = @{ $c->req->captures };
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm
index b44bf4b38..1c8a86e3a 100644
--- a/perllib/FixMyStreet/App/Model/PhotoSet.pm
+++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm
@@ -254,12 +254,25 @@ sub get_image_data {
sub delete_cached {
my ($self) = @_;
my $object = $self->object or return;
+ my $id = $object->id or return;
- unlink glob FixMyStreet->path_to(
- 'web',
- 'photo',
- $object->id . '.*'
- );
+ my @dirs = ('web', 'photo');
+ push @dirs, 'c' if ref $object eq 'FixMyStreet::DB::Result::Comment';
+
+ # Old files without an index number; will always be .jpeg
+ foreach my $size ("", ".fp", ".tn", ".full") {
+ unlink FixMyStreet->path_to(@dirs, "$id$size.jpeg");
+ }
+
+ # New files with index number
+ my @images = $self->all_ids;
+ foreach (map [ $_, $images[$_] ], 0 .. $#images) {
+ my ($i, $file) = @$_;
+ my ($fileid, $type) = split /\./, $file;
+ foreach my $size ("", ".fp", ".tn", ".full") {
+ unlink FixMyStreet->path_to(@dirs, "$id.$i$size.$type");
+ }
+ }
}
sub remove_images {