From 8b38c6d76b837f85d1e51c62b944eac41ec9697c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 2 Jun 2011 11:27:49 +0100 Subject: find() will always return result if unique key is given, so use search(). --- perllib/FixMyStreet/App/Controller/Photo.pm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Photo.pm') diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 774e5c4f7..7b2a04e4b 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -32,17 +32,25 @@ sub index :Path :Args(0) { my $comment = $c->req->param('c'); return unless ( $id || $comment ); - my $photo; - + my @photo; if ( $comment ) { - $photo = $c->model('DB::Comment')->find( {id => $comment, state => 'confirmed' } ); + @photo = $c->model('DB::Comment')->search( { + id => $comment, + state => 'confirmed', + photo => { '!=', undef }, + } ); } else { - $photo = $c->model('DB::Problem')->find( {id => $id, state => 'confirmed' } ); + @photo = $c->model('DB::Problem')->search( { + id => $id, + state => [ 'confirmed', 'fixed', 'partial' ], + photo => { '!=', undef }, + } ); } - return unless $photo; + $c->detach( '/page_error_404_not_found', [ 'No photo' ] ) + unless @photo; - $photo = $photo->photo; + my $photo = $photo[0]->photo; if ( $c->req->param('tn' ) ) { $photo = _resize( $photo, 'x100' ); } elsif ( $c->cobrand->default_photo_resize ) { -- cgit v1.2.3