Bugzilla – Attachment 152390 Details for
Bug 33047
Local cover image fetchers return 500 internal error when image not available
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33047: Return 404 instead of 500 when biblio does not exist
Bug-33047-Return-404-instead-of-500-when-biblio-do.patch (text/plain), 4.62 KB, created by
Owen Leonard
on 2023-06-15 16:48:47 UTC
(
hide
)
Description:
Bug 33047: Return 404 instead of 500 when biblio does not exist
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2023-06-15 16:48:47 UTC
Size:
4.62 KB
patch
obsolete
>From 987bfe8e5fcd36c88dfa4fe1470395ebc3582f04 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 11 May 2023 15:49:08 +0200 >Subject: [PATCH] Bug 33047: Return 404 instead of 500 when biblio does not > exist > >If the biblionumber or the itemnumber passed in parameter does not >exist we should return 404 instead of exploding with a 500. > >Test plan: >Attach cover images to biblio and items >Notice that the UI is working correctly (staff and OPAC) >Hit catalogue/image.pl and opac/opac-image.pl with non-existent >biblionumber and imagenumber >Notice that you now get 404 instead of 500 > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >--- > catalogue/image.pl | 26 ++++++++++++++++---------- > opac/opac-image.pl | 21 ++++++++++++++------- > 2 files changed, 30 insertions(+), 17 deletions(-) > >diff --git a/catalogue/image.pl b/catalogue/image.pl >index 62e1ebb7ca9..41eebc019c8 100755 >--- a/catalogue/image.pl >+++ b/catalogue/image.pl >@@ -25,15 +25,14 @@ > > use Modern::Perl; > >-use CGI qw ( -utf8 ); #qw(:standard escapeHTML); >+use CGI qw ( -utf8 ); > use C4::Context; >-use Koha::CoverImages; > use Koha::Biblios; >-use Koha::Exceptions; >+use Koha::CoverImages; > > $| = 1; > >-my $data = CGI->new; >+my $input = CGI->new; > my $imagenumber; > > =head1 NAME >@@ -60,15 +59,22 @@ imagenumber, a random image is selected. > > my ( $image ); > if ( C4::Context->preference("LocalCoverImages") ) { >- my $imagenumber = $data->param('imagenumber'); >- my $biblionumber = $data->param('biblionumber'); >+ my $imagenumber = $input->param('imagenumber'); >+ my $biblionumber = $input->param('biblionumber'); > if ( defined $imagenumber ) { >- $imagenumber = $data->param('imagenumber'); >+ $imagenumber = $input->param('imagenumber'); > $image = Koha::CoverImages->find($imagenumber); >+ unless ($image) { >+ print $input->redirect("/cgi-bin/koha/errors/404.pl"); >+ exit; >+ } > } > elsif ( defined $biblionumber ) { > my $biblio = Koha::Biblios->find($biblionumber); >- Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio; >+ unless ($biblio) { >+ print $input->redirect("/cgi-bin/koha/errors/404.pl"); >+ exit; >+ } > my $cover_images = $biblio->cover_images; > if ( $cover_images->count ) { > $image = $cover_images->next; >@@ -79,11 +85,11 @@ if ( C4::Context->preference("LocalCoverImages") ) { > $image ||= Koha::CoverImages->no_image; > > my $image_data = >- $data->param('thumbnail') >+ $input->param('thumbnail') > ? $image->thumbnail > : $image->imagefile; > >-print $data->header( >+print $input->header( > -type => $image->mimetype, > -expires => '+30m', > -Content_Length => length($image_data) >diff --git a/opac/opac-image.pl b/opac/opac-image.pl >index 56cf552eb85..040bd2d7cb5 100755 >--- a/opac/opac-image.pl >+++ b/opac/opac-image.pl >@@ -32,7 +32,7 @@ use Koha::CoverImages; > > $| = 1; > >-my $data = CGI->new; >+my $input = CGI->new; > my $imagenumber; > > =head1 NAME >@@ -59,15 +59,22 @@ imagenumber, a random image is selected. > > my ( $image ); > if ( C4::Context->preference("OPACLocalCoverImages") ) { >- my $imagenumber = $data->param('imagenumber'); >- my $biblionumber = $data->param('biblionumber'); >+ my $imagenumber = $input->param('imagenumber'); >+ my $biblionumber = $input->param('biblionumber'); > if ( defined $imagenumber ) { >- $imagenumber = $data->param('imagenumber'); >+ $imagenumber = $input->param('imagenumber'); > $image = Koha::CoverImages->find($imagenumber); >+ unless ($image) { >+ print $input->redirect("/cgi-bin/koha/errors/404.pl"); >+ exit; >+ } > } > elsif ( defined $biblionumber ) { > my $biblio = Koha::Biblios->find($biblionumber); >- Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio; >+ unless ($biblio) { >+ print $input->redirect("/cgi-bin/koha/errors/404.pl"); >+ exit; >+ } > my $cover_images = $biblio->cover_images; > if ( $cover_images->count ) { > $image = $cover_images->next; >@@ -78,11 +85,11 @@ if ( C4::Context->preference("OPACLocalCoverImages") ) { > $image ||= Koha::CoverImages->no_image; > > my $image_data = >- $data->param('thumbnail') >+ $input->param('thumbnail') > ? $image->thumbnail > : $image->imagefile; > >-print $data->header( >+print $input->header( > -type => $image->mimetype, > -expires => '+30m', > -Content_Length => length($image_data) >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33047
:
151082
|
152390
|
153226