From 188a5ecde5e85ec4d6b32377da9a3db016e38a0e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 13 Jun 2019 11:06:29 -0500 Subject: [PATCH] Bug 23117: Shortcut additem.pl on nonexistent biblionumber 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 --- C4/Output.pm | 4 ++++ cataloguing/additem.pl | 4 ++++ koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/C4/Output.pm b/C4/Output.pm index e8a86cc5ed..b107e27606 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -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}; } } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 062d335107..a7db81557b 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -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"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 2dd65df7aa..25fcf73dd2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -32,7 +32,7 @@
- + [% INCLUDE 'blocking_errors.inc' %]

Items for [% title | html %] [% IF ( author ) %] by [% author | html %][% END %] (Record #[% biblionumber | html %])

[% IF ( barcode_not_unique ) %]
Error saving item: Barcode must be unique.
[% END %] -- 2.11.0