Bug 23117: Shortcut additem.pl on nonexistent biblionumber
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 13 Jun 2019 16:06:29 +0000 (11:06 -0500)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Sat, 15 Jun 2019 07:01:37 +0000 (08:01 +0100)
To prevent additem.pl to crash when called with a nonexistent
biblionumber we are here implementing the blocking_error.inc trick to
display a friendly message instead.

Can't call method "fields" on an undefined value at
/home/vagrant/kohaclone/cataloguing/additem.pl line 736.

Test plan:
hit
/cataloguing/additem.pl?biblionumber=
/cataloguing/additem.pl?biblionumber=424242
You will get a friendly "Bibliographic record not found." message,
instead of a 500

Signed-off-by: Bin Wen <bin.wen@inlibro.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Output.pm
cataloguing/additem.pl
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt

index e8a86cc..b107e27 100644 (file)
@@ -338,6 +338,10 @@ sub output_and_exit_if_error {
             elsif( not $logged_in_user->can_see_patron_infos( $current_patron ) ) {
                 $error = 'cannot_see_patron_infos';
             }
+        } elsif ( $params->{module} eq 'cataloguing' ) {
+            # We are testing the record to avoid additem to fetch the Koha::Biblio
+            # But in the long term we will want to get a biblio in parameter
+            $error = 'unknown_biblio' unless $params->{record};
         }
     }
 
index 062d335..a7db815 100755 (executable)
@@ -421,6 +421,10 @@ $restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' &&
 
 my $tagslib = &GetMarcStructure(1,$frameworkcode);
 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
+
+output_and_exit_if_error( $input, $cookie, $template,
+    { module => 'cataloguing', record => $record } );
+
 my $oldrecord = TransformMarcToKoha($record);
 my $itemrecord;
 my $nextop="additem";
index 2dd65df..25fcf73 100644 (file)
@@ -32,7 +32,7 @@
     <div class="row">
         <div class="col-sm-12">
             <main>
-
+                [% INCLUDE 'blocking_errors.inc' %]
 <h1>Items for [% title | html %] [% IF ( author ) %] by [% author | html %][% END %] (Record #[% biblionumber | html %])</h1>
 
 [% IF ( barcode_not_unique ) %]<div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]