diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-01-08 11:27:12 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-01-08 11:27:12 +0000 |
commit | 5c1f5df6e9942f307cade6215074c3d004da14c0 (patch) | |
tree | b9b32123e698c88a517cee0849272c7a02c24912 /perllib/FixMyStreet/App/Controller/Admin.pm | |
parent | 98c4305003a7fdd468822cd45a605dd935943f72 (diff) |
Handle multiple photo rotation/removal in admin.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 0fc87c2f6..f2d6040ae 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -790,11 +790,12 @@ sub report_edit : Path('report_edit') : Args(1) { } # Deal with photos - if ( $c->get_param('remove_photo') ) { - $problem->photo(undef); + my $remove_photo_param = $self->_get_remove_photo_param($c); + if ($remove_photo_param) { + $self->remove_photo($c, $problem, $remove_photo_param); } - if ( $c->get_param('remove_photo') || $new_state eq 'hidden' ) { + if ( $remove_photo_param || $new_state eq 'hidden' ) { unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' ); } @@ -1507,6 +1508,33 @@ sub rotate_photo : Private { return 1; } +=head2 remove_photo + +Remove a photo from a report + +=cut + +# Returns index of photo(s) to remove, if any +sub _get_remove_photo_param { + my ($self, $c) = @_; + + return 'ALL' if $c->get_param('remove_photo'); + + my @keys = map { /(\d+)$/ } grep { /^remove_photo_/ } keys %{ $c->req->params } or return; + return \@keys; +} + +sub remove_photo : Private { + my ($self, $c, $object, $keys) = @_; + if ($keys eq 'ALL') { + $object->photo(undef); + } else { + my $fileids = $object->get_photoset($c)->remove_images($keys); + $object->photo($fileids); + } + return 1; +} + =head2 check_page_allowed Checks if the current catalyst action is in the list of allowed pages and |