From eb033b9438f830af011994d38683ccac10156976 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Mon, 20 Feb 2023 11:06:32 +0100 Subject: [PATCH] Bug 32418: Can't call method 'unblessed' on an undefined value at cataloguing/additem.pl Check whether the current op is edititem or dupeitem and if so check whether the itemnumber supplied as a query param actually exists. If it doesn't, redirect to the additem op and hide all UI elements except for a dialog that gives options to add a new item to the record or to view the records holdings. This behaviour was adapted from the addbiblio view, as suggested by Fridolin. To test: 1. Go to any record 2. Hit the edit button on an item in the holdings table 3. Modify the URL so that the query param for the itemnumber is either 3.1 empty: /cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=384&itemnumber= 3.2 an itemnumber that doesn't exist: /cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=384&itemnumber=9999999999 3.3 whatever else you come up with.. 4. Check the same thing for the dupe option (op=dupeitem) 5. Sign off Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi (cherry picked from commit ef803755f5892ab811a65a55fbb77d7d3d66f551) Signed-off-by: Matt Blenkinsop --- cataloguing/additem.pl | 18 ++++++++++++------ .../prog/en/modules/cataloguing/additem.tt | 14 +++++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index ed31390663..011c561b3f 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -156,6 +156,14 @@ my ($template, $loggedinuser, $cookie) flagsrequired => {editcatalogue => $userflags}, }); +if ( $op eq 'edititem' || $op eq 'dupeitem' ) { + my $item = Koha::Items->find($itemnumber); + if ( !$item ) { + $itemnumber = undef; + $template->param( item_doesnt_exist => 1 ); + output_and_exit( $input, $cookie, $template, 'unknown_item' ); + } +} # Does the user have a restricted item editing permission? my $uid = Koha::Patrons->find( $loggedinuser )->userid; @@ -463,20 +471,18 @@ if ($op eq "additem") { #------------------------------------------------------------------------------- # retrieve item if exist => then, it's a modif $current_item = Koha::Items->find($itemnumber)->unblessed; - # FIXME Handle non existent item - $nextop = "saveitem"; + $nextop = "saveitem"; #------------------------------------------------------------------------------- } elsif ($op eq "dupeitem") { #------------------------------------------------------------------------------- # retrieve item if exist => then, it's a modif $current_item = Koha::Items->find($itemnumber)->unblessed; - # FIXME Handle non existent item - if (C4::Context->preference('autoBarcode') eq 'incremental') { - my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; + if ( C4::Context->preference('autoBarcode') eq 'incremental' ) { + my ($barcode) = C4::Barcodes::ValueBuilder::incremental::get_barcode; $current_item->{barcode} = $barcode; } else { - $current_item->{barcode} = undef; # Don't save it! + $current_item->{barcode} = undef; # Don't save it! } $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 e5092464aa..e0cfba7469 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -26,7 +26,14 @@ [% INCLUDE 'str/cataloging_additem.inc' %] [% Asset.js("js/cataloging_additem.js") | $raw %] @@ -59,6 +66,11 @@
+ [% IF item_doesnt_exist %] + + [% END %] [% INCLUDE 'blocking_errors.inc' %]

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

-- 2.39.5