diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-02 11:27:49 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-02 11:28:31 +0100 |
commit | 8b38c6d76b837f85d1e51c62b944eac41ec9697c (patch) | |
tree | c4983de181c59e015dbc2d6b7f95e04198e6b992 /perllib/FixMyStreet/App/Controller/Photo.pm | |
parent | 60da5d1d852f3cf06b04110a17ba8c0e62d62c2b (diff) |
find() will always return result if unique key is given, so use search().
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Photo.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 20 |
1 files changed, 14 insertions, 6 deletions
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 ) { |