From 487865b24a91b55c5925c9b57644ddca5a0607a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <joonas.kylmala@helsinki.fi>
Date: Thu, 29 Jul 2021 19:35:47 +0300
Subject: [PATCH] Bug 28779: Skip processing of non-existent biblios

Just checking with a regex that whether an input looks like a biblionumber
is not enough, we need to also verify there is a biblio really existing
in the database and skip processing of hold request for non-existent
biblionumbers.

To test:
 1) Go to page /cgi-bin/koha/reserve/request.pl?biblionumbers=XXXXX
    where XXXXX is non-existent biblionumber, notice internal server error
 2) Apply patch
 3) Repeat step 1 and notice we cannot place a hold

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Petro Vashchuk <stalkernoid@gmail.com>
---
 reserve/request.pl | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/reserve/request.pl b/reserve/request.pl
index a6fbe528f4..df665587cf 100755
--- a/reserve/request.pl
+++ b/reserve/request.pl
@@ -307,6 +307,11 @@ foreach my $biblionumber (@biblionumbers) {
     my %biblioloopiter = ();
 
     my $biblio = Koha::Biblios->find( $biblionumber );
+    unless ($biblio) {
+        $biblioloopiter{noitems} = 1;
+        $template->param('noitems' => 1);
+        next;
+    }
 
     my $force_hold_level;
     if ( $patron ) {
-- 
2.31.1