@@ -, +, @@ - Adding an item - Updating an item - Deleting an item $ kshell k$ prove t/db_dependent/Koha/Item.t --- Koha/Item.pm | 13 +++++++++++++ t/db_dependent/Koha/Item.t | 30 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -30,6 +30,7 @@ use C4::Reserves; use C4::ClassSource qw( GetClassSort ); use C4::Log qw( logaction ); +use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; use Koha::Checkouts; use Koha::CirculationRules; use Koha::CoverImages; @@ -212,6 +213,12 @@ sub store { unless $params->{skip_record_index}; $self->get_from_storage->_after_item_action_hooks({ action => $action }); + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( + { + biblio_ids => [ $self->biblionumber ] + } + ); + return $result; } @@ -237,6 +244,12 @@ sub delete { logaction( "CATALOGUING", "DELETE", $self->itemnumber, "item" ) if C4::Context->preference("CataloguingLog"); + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( + { + biblio_ids => [ $self->biblionumber ] + } + ); + return $result; } --- a/t/db_dependent/Koha/Item.t +++ a/t/db_dependent/Koha/Item.t @@ -22,6 +22,7 @@ use utf8; use Test::More tests => 15; use Test::Exception; +use Test::MockModule; use C4::Biblio qw( GetMarcSubfieldStructure ); use C4::Circulation qw( AddIssue AddReturn ); @@ -1170,7 +1171,7 @@ subtest 'columns_to_str' => sub { subtest 'store() tests' => sub { - plan tests => 1; + plan tests => 2; subtest '_set_found_trigger() tests' => sub { @@ -1223,6 +1224,33 @@ subtest 'store() tests' => sub { $schema->storage->txn_rollback; }; + + subtest 'holds_queue update tests' => sub { + + plan tests => 2; + + $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 ], + '->store triggers a holds queue update for the related biblio' + ); + } ); + + # new item + my $item = $builder->build_sample_item({ biblionumber => $biblio->id }); + + # updated item + $item->set({ reserves => 1 })->store; + + $schema->storage->txn_rollback; + }; }; subtest 'Recalls tests' => sub { --