From a45e79c1f4fc6cb168a75a11b79e9145e65321d5 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Oct 2023 09:53:19 -0300 Subject: [PATCH] Bug 31692: Tidy and rebase fix Signed-off-by: Tomas Cohen Arazi --- Koha/Hold.pm | 22 +++++++++------ reserve/modrequest.pl | 4 +-- reserve/request.pl | 18 +++++++----- t/db_dependent/Koha/Hold.t | 56 +++++++++++++++++++++----------------- 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 2c30f915b3..1a1a859bca 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -866,21 +866,25 @@ a patron on a record to be alike. sub change_type { my ( $self, $itemnumber ) = @_; - my $record_holds_per_patron = Koha::Holds->search( { - borrowernumber => $self->borrowernumber, - biblionumber => $self->biblionumber, - } ); + my $record_holds_per_patron = Koha::Holds->search( + { + borrowernumber => $self->borrowernumber, + biblionumber => $self->biblionumber, + } + ); if ( $itemnumber && $self->itemnumber ) { - $self->itemnumber( $itemnumber )->store; + $self->itemnumber($itemnumber)->store; return $self; } if ( $record_holds_per_patron->count == 1 ) { - $self->set({ - itemnumber => $itemnumber ? $itemnumber : undef, - item_level_hold => $itemnumber ? 1 : 0, - })->store; + $self->set( + { + itemnumber => $itemnumber ? $itemnumber : undef, + item_level_hold => $itemnumber ? 1 : 0, + } + )->store; } else { Koha::Exceptions::Hold::CannotChangeHoldType->throw(); } diff --git a/reserve/modrequest.pl b/reserve/modrequest.pl index e41e999d64..e9a4c1b2a7 100755 --- a/reserve/modrequest.pl +++ b/reserve/modrequest.pl @@ -96,13 +96,13 @@ else { try { $hold->change_type; } catch { - if ($_->isa('Koha::Exceptions::Hold::CannotChangeHoldType')){ + if ( $_->isa('Koha::Exceptions::Hold::CannotChangeHoldType') ) { warn $_; } else { $_->rethrow; } } - }; + } } my @biblio_ids = uniq @biblionumber; Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( diff --git a/reserve/request.pl b/reserve/request.pl index e9f420ec94..0e5b60f056 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -579,13 +579,17 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) $template->param( always_show_holds => $always_show_holds ); my $show_holds_now = $input->param('show_holds_now'); unless( (defined $always_show_holds && $always_show_holds eq 'DONT') && !$show_holds_now ){ - my $holds_count_per_patron = { map { $_->{borrowernumber} => $_->{hold_count} } - @{ Koha::Holds->search( { biblionumber=> $biblionumber }, { - select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ], - as => [ qw( borrowernumber hold_count ) ], - group_by => [ qw( borrowernumber ) ] } - )->unblessed - } }; + my $holds_count_per_patron = { + map { $_->{borrowernumber} => $_->{hold_count} } @{ Koha::Holds->search( + { biblionumber => $biblionumber }, + { + select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ], + as => [qw( borrowernumber hold_count )], + group_by => [qw( borrowernumber )] + } + )->unblessed + } + }; my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list; foreach my $res ( sort { diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index 563af986c9..aa7f677f64 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use Test::Exception; use Test::MockModule; @@ -998,33 +998,37 @@ subtest 'Koha::Hold::item_group tests' => sub { $schema->storage->txn_rollback; }; -subtest 'change_type tests' => sub { +subtest 'change_type() tests' => sub { plan tests => 13; $schema->storage->txn_begin; my $item = $builder->build_object( { class => 'Koha::Items', } ); - my $hold = $builder->build_object( { - class => 'Koha::Holds', - value => { - itemnumber => undef, - item_level_hold => 0, + my $hold = $builder->build_object( + { + class => 'Koha::Holds', + value => { + itemnumber => undef, + item_level_hold => 0, + } } - } ); + ); - my $hold2 = $builder->build_object( { - class => 'Koha::Holds', - value => { - borrowernumber => $hold->borrowernumber, + my $hold2 = $builder->build_object( + { + class => 'Koha::Holds', + value => { + borrowernumber => $hold->borrowernumber, + } } - } ); + ); ok( $hold->change_type ); $hold->discard_changes; - is( $hold->itemnumber, undef, 'record hold to record hold, no changes'); + is( $hold->itemnumber, undef, 'record hold to record hold, no changes' ); is( $hold->item_level_hold, 0, 'item_level_hold=0' ); @@ -1032,7 +1036,7 @@ subtest 'change_type tests' => sub { $hold->discard_changes; - is( $hold->itemnumber, $item->itemnumber, 'record hold to item hold'); + is( $hold->itemnumber, $item->itemnumber, 'record hold to item hold' ); is( $hold->item_level_hold, 1, 'item_level_hold=1' ); @@ -1040,7 +1044,7 @@ subtest 'change_type tests' => sub { $hold->discard_changes; - is( $hold->itemnumber, $item->itemnumber, 'item hold to item hold, no changes'); + is( $hold->itemnumber, $item->itemnumber, 'item hold to item hold, no changes' ); is( $hold->item_level_hold, 1, 'item_level_hold=1' ); @@ -1048,21 +1052,23 @@ subtest 'change_type tests' => sub { $hold->discard_changes; - is( $hold->itemnumber, undef, 'item hold to record hold'); + is( $hold->itemnumber, undef, 'item hold to record hold' ); is( $hold->item_level_hold, 0, 'item_level_hold=0' ); - my $hold3 = $builder->build_object( { - class => 'Koha::Holds', - value => { - biblionumber => $hold->biblionumber, - borrowernumber => $hold->borrowernumber, + my $hold3 = $builder->build_object( + { + class => 'Koha::Holds', + value => { + biblionumber => $hold->biblionumber, + borrowernumber => $hold->borrowernumber, + } } - } ); + ); throws_ok { $hold->change_type } - 'Koha::Exceptions::Hold::CannotChangeHoldType', - 'Exception thrown because more than one hold per record'; + 'Koha::Exceptions::Hold::CannotChangeHoldType', + 'Exception thrown because more than one hold per record'; $schema->storage->txn_rollback; }; -- 2.39.5