From fef55e2e3f8e70dfff64f436c0d6c736f48680be Mon Sep 17 00:00:00 2001 From: LMSCloudPaulD Date: Fri, 23 Dec 2022 10:07:01 +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 the item is not defined we output_and_exit and save the time to execute the rest of the controller code. Additionally we now don't have to process the whole template anymore. The only caveat is that we now have the suggested actions above the actual error message. Still an improvement. though. Again, thanks Frido. Hope, that this is what you had in mind. 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 --- cataloguing/additem.pl | 26 ++++++++----------- .../prog/en/modules/cataloguing/additem.tt | 11 ++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index d180823d45..760d0d774c 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -161,6 +161,7 @@ if ( $op eq "edititem" || $op eq "dupeitem" ) { if ( !$item ) { $itemnumber = undef; $template->param( item_doesnt_exist => 1 ); + output_and_exit( $input, $cookie, $template, 'unknown_item' ) } } @@ -469,25 +470,20 @@ if ($op eq "additem") { } elsif ($op eq "edititem") { #------------------------------------------------------------------------------- # retrieve item if exist => then, it's a modif - $nextop = "additem"; - if ($itemnumber) { - $current_item = Koha::Items->find($itemnumber)->unblessed; - $nextop = "saveitem"; - } + $current_item = Koha::Items->find($itemnumber)->unblessed; + $nextop = "saveitem"; #------------------------------------------------------------------------------- } elsif ($op eq "dupeitem") { #------------------------------------------------------------------------------- # retrieve item if exist => then, it's a modif - if ($itemnumber) { - $current_item = Koha::Items->find($itemnumber)->unblessed; - 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 = Koha::Items->find($itemnumber)->unblessed; + 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! } $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 7a6f88a1ac..c57a568be9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -66,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 %])

@@ -77,12 +82,6 @@ [% IF ( linked_analytics ) %]
Cannot delete: item has linked analytics..
[% END %] [% IF last_item_for_hold %]
Cannot delete: Last item for bibliographic record with biblio-level hold on it.
[% END %] [% IF item_not_found %]
Cannot delete: Item not found.
[% END %] -[% IF item_doesnt_exist %] -
-The item you are trying to access doesn't exist.
-Add a new item or go to the records holdings. -
-[% END %]
[% IF items %] -- 2.30.2