From f6f28e2265207d5153a648ac6ff5a7b56392ed90 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Fri, 18 Oct 2024 09:58:19 +0000 Subject: [PATCH] Bug 35906: (QA follow-up) Refactor (slightly) to reduce complexity in Koha/Item(s).pm, catalogue/updateitem Signed-off-by: Paul Derscheid Signed-off-by: Katrin Fischer --- Koha/Item.pm | 2 +- Koha/Items.pm | 30 +++++++++++++++++++++--------- catalogue/updateitem.pl | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 3e3c1a6252..16f66a8c68 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1928,7 +1928,7 @@ Returns the effective bookability of the current item, be that item or itemtype sub effective_bookable { my ($self) = @_; - return defined( $self->bookable ) ? $self->bookable : $self->itemtype->bookable; + return $self->bookable // $self->itemtype->bookable; } =head3 orders diff --git a/Koha/Items.pm b/Koha/Items.pm index ba9d87da48..1cb1dce1b5 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -197,17 +197,29 @@ Returns a new resultset, containing only those items that are allowed to be book sub filter_by_bookable { my ($self) = @_; - my @bookable_itemtypes = Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype'); - - my ( $where, $attr ); - if ( C4::Context->preference("item-level_itypes") ) { - $where = [ { bookable => 1 }, { bookable => undef, itype => { -in => \@bookable_itemtypes } } ]; - } else { - $where = [ { bookable => 1 }, { bookable => undef, 'biblioitem.itemtype' => { -in => \@bookable_itemtypes } } ]; - $attr = { join => 'biblioitem' }; + if ( !C4::Context->preference('item-level_itypes') ) { + return $self->search( + [ + { bookable => 1 }, + { + bookable => undef, + 'biblioitem.itemtype' => + { -in => [ Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype') ] } + }, + ], + { join => 'biblioitem' } + ); } - return $self->search( $where, $attr ); + return $self->search( + [ + { bookable => 1 }, + { + bookable => undef, + itype => { -in => [ Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype') ] } + }, + ] + ); } =head3 move_to_biblio diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index 087dd98f8a..cb92efbb16 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -77,7 +77,7 @@ elsif ( $op eq "cud-set_public_note" ) { # i.e., itemnotes parameter passed from $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority); $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&"; } elsif ( $op eq "cud-set_bookable" && $bookable ne $item_data_hashref->{'bookable'} ) { - undef($bookable) if $bookable eq ""; + undef $bookable if $bookable eq q{}; $item->bookable($bookable); } elsif ( $op eq "cud-set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) { $item->damaged($damaged); -- 2.39.5