From 70cccaa7e695a97e01915b7e66fbf20730659170 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 3 Jan 2020 13:27:16 +0000 Subject: [PATCH] Bug 24331: Don't die on items with no type To test: 1 - Find or create an item with no itemtype set 2 - Attempt to place a hold 3 - INternal server error 4 - Apply patch 5 - Repeat 6 - No error 7 - Set the items itemtype to an itemtype marked not for loan 8 - Set circ rules to allow holds on this itemtype 9 - Attempt to place hold, item is not holdable 10 - Remove not for loan from itemtype 11 - Item is holdable Signed-off-by: Myka Kennedy Stephens --- C4/Reserves.pm | 4 ++-- t/db_dependent/Reserves.t | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 05d5910812..4e384dc900 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1209,8 +1209,8 @@ sub IsAvailableForItemLevelRequest { # FIXME - a lot of places in the code do this # or something similar - need to be # consolidated - my $itemtype = $item->effective_itemtype; - my $notforloan_per_itemtype = Koha::ItemTypes->find($itemtype)->notforloan; + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); + my $notforloan_per_itemtype = defined $itemtype ? $itemtype->notforloan : 0; return 0 if $notforloan_per_itemtype || diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 618f0598c9..2c8ed070c4 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,9 +17,10 @@ use Modern::Perl; -use Test::More tests => 62; +use Test::More tests => 64; use Test::MockModule; use Test::Warn; +use Test::Exception; use t::lib::Mocks; use t::lib::TestBuilder; @@ -533,6 +534,13 @@ $item = Koha::Items->find($itemnumber); ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" ); +# Tests for items not for loan status, bug 24331 +my $item_no_type = $builder->build_sample_item({ itype => undef }); +lives_ok{ C4::Reserves::IsAvailableForItemLevelRequest($item_no_type, $patron) } "Reserving a book on item level with no itemtype"; +my $itemtype_notforloan = $builder->build_object({ class => 'Koha::ItemTypes', value => { notforloan => 1 } })->itemtype; +my $item_notforloan = $builder->build_sample_item({ itype => $itemtype_notforloan }); +is( C4::Reserves::IsAvailableForItemLevelRequest($item_notforloan, $patron), 0, "Item not available if itemtype notforloan" ); + my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode }; t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); -- 2.11.0