From e57a033b3baf17ea4187f8385c32be7c19041586 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 15 May 2025 18:27:07 +0000 Subject: [PATCH] Bug 39912: Update RealTimeHoldsQueue when hold pickup location is updated When a hold's pickup location is changed we should rebuild the holds queue. To test: 1 - Enable RealTimeHoldsQueue 2 - Enable LocalHoldsPriority where pickup library matches home library 3 - Place two biblio level holds on a bib with one item for two different patrons for delivery to a different library then the home library 4 - Check the queue - firstpatron should have priority 5 - Change the pickup location for the second hold to be picked up at the home library 6 - Check the queue, unchanged 7 - Change the pickup location back 8 - Apply patch, restart all 9 - Change the pickup location to the items home library again 10 - Check the queue 11 - Second patron has now been given priority Signed-off-by: Michelle Spinney Signed-off-by: Martin Renvoize --- Koha/Hold.pm | 3 +++ t/db_dependent/Koha/Hold.t | 48 ++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 8f0cd75ac2f..59b498a7d22 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -972,6 +972,9 @@ sub store { } } } + if ( exists $updated_columns{branchcode} ) { + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $self->biblionumber ] } ); + } } $self = $self->SUPER::store; diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index 4b84be57447..46581eb6e03 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -346,25 +346,28 @@ subtest 'fill() tests' => sub { subtest 'holds_queue update tests' => sub { - plan tests => 1; + plan tests => 2; my $biblio = $builder->build_sample_biblio; - my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); + # The check of the pref is in the Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue + # so we mock the base enqueue method here to see if it is called + my $mock = Test::MockModule->new('Koha::BackgroundJob'); $mock->mock( 'enqueue', sub { my ( $self, $args ) = @_; is_deeply( - $args->{biblio_ids}, + $args->{job_args}->{biblio_ids}, [ $biblio->id ], - '->fill triggers a holds queue update for the related biblio' + 'when pref enabled the previous action triggers a holds queue update for the related biblio' ); } ); t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); + diag("Filling a hold when pref enabled should trigger a test"); $builder->build_object( { class => 'Koha::Holds', @@ -376,7 +379,7 @@ subtest 'fill() tests' => sub { t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); - # this call shouldn't add a new test + diag("Filling a hold when pref disabled should not trigger a test"); $builder->build_object( { class => 'Koha::Holds', @@ -385,6 +388,41 @@ subtest 'fill() tests' => sub { } } )->fill; + + my $library_1 = $builder->build_object( + { + class => 'Koha::Libraries', + } + )->store; + my $library_2 = $builder->build_object( + { + class => 'Koha::Libraries', + } + )->store; + + my $hold = $builder->build_object( + { + class => 'Koha::Holds', + value => { + biblionumber => $biblio->id, + branchcode => $library_1->branchcode, + } + } + )->store; + + # Pref is off, no test triggered + diag("Updating a hold location when pref disabled should not trigger a test"); + $hold->branchcode( $library_2->branchcode )->store; + + t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); + diag("Updating a hold location when pref enabled should trigger a test"); + + # Pref is on, test triggered + $hold->branchcode( $library_1->branchcode )->store; + + diag("Update with no change to pickup location should not trigger a test"); + $hold->branchcode( $library_1->branchcode )->store; + }; $schema->storage->txn_rollback; -- 2.49.0