sub delete_photos { my $self = shift; my $q = $self->query; my $other_photos = $schema->resultset('Photos')->search( { user_id => $q->url_param('user'), } ); my @photos_to_delete = (); my @photo_ids = $q->param('delete'); while ( my $photos = $other_photos->next ) { for ( @photo_ids ) { if ( $photos->photo_id == $_ ) { push @photos_to_delete, { photo_path => $photos->photo_path, photo_id => $photos->photo_id }; } } } unless ( $q->param('is_sure') ) { return $self->tt_process('delete_photo_confirm.tt', { title => 'Photo delete confirm', c => $q, photos => \@photos_to_delete, } ); } else { $schema->resultset('Photos')->search( { user_id => $q->url_param('user'), photo_id => @photo_ids, # attempt at recursive delete } )->delete or die $!; } unlink $_ for @photos_to_delete or die $!; return "Photos deleted!"; } #### [% INCLUDE 'header.tt' %]

Are you sure?

You have selected these photos to delete:

[% FOREACH p = photos %]

[% END %]
[% INCLUDE 'footer.tt' %]