Bug 29346: Item action trigger

This patch makes the following actions trigger a holds queue rebuild for
the related biblio:

- Adding an item
- Updating an item
- Deleting an item

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Item.t
=> SUCCESS: Tests pass! Background job scheduled
3. Sign off :-D

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomás Cohen Arazi 2022-03-23 12:36:32 -03:00 committed by Fridolin Somers
parent a6d501ad8a
commit 1646d8be3e
2 changed files with 42 additions and 1 deletions

View file

@ -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;
}

View file

@ -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 {