From 2adfffe310b64d88ec853551e9181441e79fe75a 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 --- 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 84a1088a9b..2c8c5436a9 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1885,7 +1885,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 82df7df341..5a8f14c8a6 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -191,17 +191,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.47.0