Bugzilla – Attachment 131813 Details for
Bug 29346
Real-time holds queue update
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29346: Hold actions triggers
Bug-29346-Hold-actions-triggers.patch (text/plain), 7.89 KB, created by
Tomás Cohen Arazi
on 2022-03-16 20:43:20 UTC
(
hide
)
Description:
Bug 29346: Hold actions triggers
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2022-03-16 20:43:20 UTC
Size:
7.89 KB
patch
obsolete
>From 48aaea5a59aad043512f4158ccebbd0d3885c986 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 16 Mar 2022 17:22:28 -0300 >Subject: [PATCH] Bug 29346: Hold actions triggers > >This patch makes several holds related actions schedule the background >job for real-time update of the holds queue. > >This actions are: > >- place (C4::Reserves::AddReserve) >- fill (Koha::Hold->fill) >- cancel (Koha::Hold->cancel) >- suspend (Koha::Hold->suspend) >- resume (Koha::Hold->resume) > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Hold.t \ > t/db_dependent/Reserves.t >=> SUCCESS: Tests pass! Triggers are triggered >3. Sign off :-D > >Sponsored-by: Montgomery County Public Libraries >--- > C4/Reserves.pm | 7 +++ > Koha/Hold.pm | 26 +++++++++++ > t/db_dependent/Koha/Hold.t | 95 ++++++++++++++++++++++++++++++++++++-- > t/db_dependent/Reserves.t | 33 ++++++++++++- > 4 files changed, 157 insertions(+), 4 deletions(-) > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 54af13d7f0..3ae2c885c3 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -32,6 +32,7 @@ use C4::Log qw( logaction ); > use C4::Members::Messaging; > use C4::Members; > use Koha::Account::Lines; >+use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > use Koha::Biblios; > use Koha::Calendar; > use Koha::CirculationRules; >@@ -306,6 +307,12 @@ sub AddReserve { > > Koha::Plugins->call('after_hold_create', $hold); > >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $biblionumber ] >+ } >+ ); >+ > return $reserve_id; > } > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index d4fb0e4c52..cf174c0119 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -36,6 +36,8 @@ use Koha::Old::Holds; > use Koha::Calendar; > use Koha::Plugins; > >+use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; >+ > use Koha::Exceptions::Hold; > > use base qw(Koha::Object); >@@ -124,6 +126,12 @@ sub suspend_hold { > logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, $self ) > if C4::Context->preference('HoldsLog'); > >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $self->biblionumber ] >+ } >+ ); >+ > return $self; > } > >@@ -152,6 +160,12 @@ sub resume { > logaction( 'HOLDS', 'RESUME', $self->reserve_id, $self ) > if C4::Context->preference('HoldsLog'); > >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $self->biblionumber ] >+ } >+ ); >+ > return $self; > } > >@@ -607,6 +621,12 @@ sub cancel { > > C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, $self ) > if C4::Context->preference('HoldsLog'); >+ >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $old_me->biblionumber ] >+ } >+ ); > } > ); > return $self; >@@ -671,6 +691,12 @@ sub fill { > > C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self ) > if C4::Context->preference('HoldsLog'); >+ >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $old_me->biblionumber ] >+ } >+ ); > } > ); > return $self; >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 0c1776daa9..77f7938d30 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 => 5; >+use Test::More tests => 6; > > use Test::Exception; > use Test::MockModule; >@@ -38,7 +38,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'fill() tests' => sub { > >- plan tests => 12; >+ plan tests => 13; > > $schema->storage->txn_begin; > >@@ -233,6 +233,32 @@ subtest 'fill() tests' => sub { > ); > }; > >+ subtest 'holds_queue update tests' => sub { >+ >+ plan tests => 1; >+ >+ my $biblio = $builder->build_sample_biblio; >+ >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( 'enqueue', sub { >+ my ( $self, $args ) = @_; >+ is_deeply( >+ $args->{biblio_ids}, >+ [ $biblio->id ], >+ '->fill triggers a holds queue update for the related biblio' >+ ); >+ } ); >+ >+ $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ } >+ } >+ )->fill; >+ }; >+ > $schema->storage->txn_rollback; > }; > >@@ -456,7 +482,7 @@ subtest 'is_pickup_location_valid() tests' => sub { > > subtest 'cancel() tests' => sub { > >- plan tests => 5; >+ plan tests => 6; > > $schema->storage->txn_begin; > >@@ -526,5 +552,68 @@ subtest 'cancel() tests' => sub { > 'Patron link is set to the configured anonymous patron immediately' > ); > >+ subtest 'holds_queue update tests' => sub { >+ >+ plan tests => 1; >+ >+ my $biblio = $builder->build_sample_biblio; >+ >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( 'enqueue', sub { >+ my ( $self, $args ) = @_; >+ is_deeply( >+ $args->{biblio_ids}, >+ [ $biblio->id ], >+ '->cancel triggers a holds queue update for the related biblio' >+ ); >+ } ); >+ >+ $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ } >+ } >+ )->cancel; >+ }; >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'suspend_hold() and resume() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $action; >+ >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( 'enqueue', sub { >+ my ( $self, $args ) = @_; >+ is_deeply( >+ $args->{biblio_ids}, >+ [ $biblio->id ], >+ "->$action triggers a holds queue update for the related biblio" >+ ); >+ } ); >+ >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ } >+ } >+ ); >+ >+ $action = 'suspend_hold'; >+ $hold->suspend_hold; >+ >+ $action = 'resume'; >+ $hold->resume; >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t >index 9616d8f160..c93987e17a 100755 >--- a/t/db_dependent/Reserves.t >+++ b/t/db_dependent/Reserves.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 69; >+use Test::More tests => 70; > use Test::MockModule; > use Test::Warn; > >@@ -1397,3 +1397,34 @@ subtest 'IsAvailableForItemLevelRequest() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'AddReserve() tests' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $biblio = $builder->build_sample_biblio; >+ >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( 'enqueue', sub { >+ my ( $self, $args ) = @_; >+ is_deeply( >+ $args->{biblio_ids}, >+ [ $biblio->id ], >+ "AddReserve triggers a holds queue update for the related biblio" >+ ); >+ } ); >+ >+ AddReserve( >+ { >+ branchcode => $library->branchcode, >+ borrowernumber => $patron->id, >+ biblionumber => $biblio->id, >+ } >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.32.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29346
:
131088
|
131089
|
131811
|
131812
|
131813
|
131815
|
132078
|
132079
|
132080
|
132081
|
132082
|
132083
|
133183
|
133184
|
133185
|
133186
|
133187
|
133188
|
133189
|
133190
|
133191
|
133205
|
133991
|
133992
|
133993
|
133994
|
133995
|
133996
|
133997
|
133998
|
133999
|
134000
|
134001
|
134010
|
134225
|
134227
|
134309
|
134310
|
134311
|
134312
|
134313
|
134314
|
134315
|
134316
|
134317
|
134318
|
134319
|
134320
|
134321
|
134322
|
134328
|
134329
|
134330
|
134331
|
134332
|
134333
|
134334
|
134335
|
134336
|
134337
|
134338
|
134339
|
134340
|
134341
|
134342
|
134343