Bugzilla – Attachment 132082 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: Biblio actions triggers
Bug-29346-Biblio-actions-triggers.patch (text/plain), 5.09 KB, created by
Tomás Cohen Arazi
on 2022-03-23 19:36:25 UTC
(
hide
)
Description:
Bug 29346: Biblio actions triggers
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2022-03-23 19:36:25 UTC
Size:
5.09 KB
patch
obsolete
>From bbac3889d75aec2ad96c8bb9b44b5310bb42c9b0 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 23 Mar 2022 11:22:52 -0300 >Subject: [PATCH] Bug 29346: Biblio actions triggers > >This patch adds the trigger for the holds queue update on teh following >methods: > >- C4::Biblio::DelBiblio >- C4::Biblio::ModBiblio > >The ModBiblio use case could be improved by checking if itemtype is one >of the updated attributes... but it felt there was no way to do it >without some overhead. So I leave it as-is. > >It also mocks the ->enqueue method in the tests that call DelBiblio and >ModBiblio to avoid breakages [1] > >Tests are added to check the trigger is called. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Biblio.t >=> SUCCESS: Tests pass! It means the trigger is triggered :-D >3. Sign off :-D > >[1] This breakages could be avoided if we solve Koha/BackgrounJob.pm:101 >FIXME. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Biblio.pm | 16 ++++++++++++++- > t/db_dependent/Biblio.t | 45 ++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 59 insertions(+), 2 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index c4de6b064d..d438688e2d 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -106,6 +106,7 @@ use Koha::Logger; > use Koha::Caches; > use Koha::Authority::Types; > use Koha::Acquisition::Currencies; >+use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > use Koha::Biblio::Metadatas; > use Koha::Holds; > use Koha::ItemTypes; >@@ -428,6 +429,12 @@ sub ModBiblio { > C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record); > } > >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $biblionumber ] >+ } >+ ); >+ > return 1; > } > >@@ -490,7 +497,8 @@ sub DelBiblio { > # We delete any existing holds > my $holds = $biblio->holds; > while ( my $hold = $holds->next ) { >- $hold->cancel; >+ # no need to update the holds queue on each step, we'll do it at the end >+ $hold->cancel({ skip_holds_queue => 1 }); > } > > unless ( $params->{skip_record_index} ){ >@@ -519,6 +527,12 @@ sub DelBiblio { > > logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog"); > >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >+ { >+ biblio_ids => [ $biblionumber ] >+ } >+ ); >+ > return; > } > >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index ff0857a296..1287aa57c5 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -251,6 +251,9 @@ sub run_tests { > # roll back ES index changes. > t::lib::Mocks::mock_preference('SearchEngine', 'Zebra'); > >+ my $bgj_mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $bgj_mock->mock( 'enqueue', undef ); >+ > my $isbn = '0590353403'; > my $title = 'Foundation'; > my $subtitle1 = 'Research'; >@@ -636,6 +639,9 @@ subtest 'IsMarcStructureInternal' => sub { > subtest 'deletedbiblio_metadata' => sub { > plan tests => 2; > >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( 'enqueue', undef ); >+ > my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); > my $biblio_metadata = C4::Biblio::GetXmlBiblio( $biblionumber ); > C4::Biblio::DelBiblio( $biblionumber ); >@@ -646,7 +652,11 @@ subtest 'deletedbiblio_metadata' => sub { > }; > > subtest 'DelBiblio' => sub { >- plan tests => 5; >+ >+ plan tests => 6; >+ >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( 'enqueue', undef ); > > my ($biblionumber, $biblioitemnumber) = C4::Biblio::AddBiblio(MARC::Record->new, ''); > my $deleted = C4::Biblio::DelBiblio( $biblionumber ); >@@ -684,6 +694,39 @@ subtest 'DelBiblio' => sub { > is( $subscription->get_from_storage, undef, 'subscription should be deleted on biblio deletion' ); > is( $serial->get_from_storage, undef, 'serial should be deleted on biblio deletion' ); > is( $subscription_history->get_from_storage, undef, 'subscription history should be deleted on biblio deletion' ); >+ >+ subtest 'holds_queue update tests' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ 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' >+ ); >+ } ); >+ >+ # add a hold >+ $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ } >+ } >+ ); >+ >+ C4::Biblio::DelBiblio( $biblio->id ); >+ >+ $schema->storage->txn_rollback; >+ }; > }; > > subtest 'MarcFieldForCreatorAndModifier' => sub { >-- >2.35.1
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