From f0b882ac607667ab8fef04fda314e1c03dc20920 Mon Sep 17 00:00:00 2001 From: LMSCloudPaulD Date: Fri, 16 Dec 2022 09:58:15 +0100 Subject: [PATCH] Bug 32418 - Can't call method 'unblessed' on an undefined value at cataloguing/additem.pl Check whether result of Koha::Items->find is defined before invoking unblessed. If undef, redirect to additem op. --- cataloguing/additem.pl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 4c1a015f62..84a4e67140 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -462,14 +462,24 @@ if ($op eq "additem") { } elsif ($op eq "edititem") { #------------------------------------------------------------------------------- # retrieve item if exist => then, it's a modif - $current_item = Koha::Items->find($itemnumber)->unblessed or undef; + if (my $item = Koha::Items->find($itemnumber)) { + $current_item = $item->unblessed; + } else { + $current_item = undef; + } + $nextop = $current_item ? "saveitem" : "additem"; #------------------------------------------------------------------------------- } elsif ($op eq "dupeitem") { #------------------------------------------------------------------------------- # retrieve item if exist => then, it's a modif - $current_item = Koha::Items->find($itemnumber)->unblessed or undef; - if (!$current_item) { $nextop = "additem"; last; } + if (my $item = Koha::Items->find($itemnumber)) { + $current_item = $item->unblessed; + } else { + $current_item = undef; + } + + if (!$current_item) { $nextop = "additem"; return; } if (C4::Context->preference('autoBarcode') eq 'incremental') { my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; $current_item->{barcode} = $barcode; -- 2.37.1 (Apple Git-137.1)