View | Details | Raw Unified | Return to bug 29346
Collapse All | Expand All

(-)a/C4/Reserves.pm (+7 lines)
Lines 33-38 use C4::Log qw( logaction ); Link Here
33
use C4::Members::Messaging;
33
use C4::Members::Messaging;
34
use C4::Members;
34
use C4::Members;
35
use Koha::Account::Lines;
35
use Koha::Account::Lines;
36
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
36
use Koha::Biblios;
37
use Koha::Biblios;
37
use Koha::Calendar;
38
use Koha::Calendar;
38
use Koha::CirculationRules;
39
use Koha::CirculationRules;
Lines 307-312 sub AddReserve { Link Here
307
308
308
    Koha::Plugins->call('after_hold_create', $hold);
309
    Koha::Plugins->call('after_hold_create', $hold);
309
310
311
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
312
        {
313
            biblio_ids => [ $biblionumber ]
314
        }
315
    );
316
310
    return $reserve_id;
317
    return $reserve_id;
311
}
318
}
312
319
(-)a/Koha/Hold.pm (-1 / +28 lines)
Lines 36-41 use Koha::Old::Holds; Link Here
36
use Koha::Calendar;
36
use Koha::Calendar;
37
use Koha::Plugins;
37
use Koha::Plugins;
38
38
39
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
40
39
use Koha::Exceptions::Hold;
41
use Koha::Exceptions::Hold;
40
42
41
use base qw(Koha::Object);
43
use base qw(Koha::Object);
Lines 124-129 sub suspend_hold { Link Here
124
    logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, $self )
126
    logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, $self )
125
        if C4::Context->preference('HoldsLog');
127
        if C4::Context->preference('HoldsLog');
126
128
129
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
130
        {
131
            biblio_ids => [ $self->biblionumber ]
132
        }
133
    );
134
127
    return $self;
135
    return $self;
128
}
136
}
129
137
Lines 152-157 sub resume { Link Here
152
    logaction( 'HOLDS', 'RESUME', $self->reserve_id, $self )
160
    logaction( 'HOLDS', 'RESUME', $self->reserve_id, $self )
153
        if C4::Context->preference('HoldsLog');
161
        if C4::Context->preference('HoldsLog');
154
162
163
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
164
        {
165
            biblio_ids => [ $self->biblionumber ]
166
        }
167
    );
168
155
    return $self;
169
    return $self;
156
}
170
}
157
171
Lines 516-523 sub is_suspended { Link Here
516
530
517
my $cancel_hold = $hold->cancel(
531
my $cancel_hold = $hold->cancel(
518
    {
532
    {
519
        [ charge_cancel_fee => 1||0, ]
533
        [ charge_cancel_fee   => 1||0, ]
520
        [ cancellation_reason => $cancellation_reason, ]
534
        [ cancellation_reason => $cancellation_reason, ]
535
        [ skip_holds_queue    => 1||0 ]
521
    }
536
    }
522
);
537
);
523
538
Lines 607-612 sub cancel { Link Here
607
622
608
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, $self )
623
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, $self )
609
                if C4::Context->preference('HoldsLog');
624
                if C4::Context->preference('HoldsLog');
625
626
            Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
627
                {
628
                    biblio_ids => [ $old_me->biblionumber ]
629
                }
630
            ) unless $params->{skip_holds_queue};
610
        }
631
        }
611
    );
632
    );
612
    return $self;
633
    return $self;
Lines 671-676 sub fill { Link Here
671
692
672
            C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self )
693
            C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self )
673
                if C4::Context->preference('HoldsLog');
694
                if C4::Context->preference('HoldsLog');
695
696
            Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
697
                {
698
                    biblio_ids => [ $old_me->biblionumber ]
699
                }
700
            );
674
        }
701
        }
675
    );
702
    );
676
    return $self;
703
    return $self;
(-)a/t/db_dependent/Koha/Hold.t (-3 / +102 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 38-44 my $builder = t::lib::TestBuilder->new; Link Here
38
38
39
subtest 'fill() tests' => sub {
39
subtest 'fill() tests' => sub {
40
40
41
    plan tests => 12;
41
    plan tests => 13;
42
42
43
    $schema->storage->txn_begin;
43
    $schema->storage->txn_begin;
44
44
Lines 233-238 subtest 'fill() tests' => sub { Link Here
233
        );
233
        );
234
    };
234
    };
235
235
236
    subtest 'holds_queue update tests' => sub {
237
238
        plan tests => 1;
239
240
        my $biblio = $builder->build_sample_biblio;
241
242
        my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
243
        $mock->mock( 'enqueue', sub {
244
            my ( $self, $args ) = @_;
245
            is_deeply(
246
                $args->{biblio_ids},
247
                [ $biblio->id ],
248
                '->fill triggers a holds queue update for the related biblio'
249
            );
250
        } );
251
252
        $builder->build_object(
253
            {
254
                class => 'Koha::Holds',
255
                value => {
256
                    biblionumber   => $biblio->id,
257
                }
258
            }
259
        )->fill;
260
    };
261
236
    $schema->storage->txn_rollback;
262
    $schema->storage->txn_rollback;
237
};
263
};
238
264
Lines 456-462 subtest 'is_pickup_location_valid() tests' => sub { Link Here
456
482
457
subtest 'cancel() tests' => sub {
483
subtest 'cancel() tests' => sub {
458
484
459
    plan tests => 5;
485
    plan tests => 6;
460
486
461
    $schema->storage->txn_begin;
487
    $schema->storage->txn_begin;
462
488
Lines 526-530 subtest 'cancel() tests' => sub { Link Here
526
        'Patron link is set to the configured anonymous patron immediately'
552
        'Patron link is set to the configured anonymous patron immediately'
527
    );
553
    );
528
554
555
    subtest 'holds_queue update tests' => sub {
556
557
        plan tests => 1;
558
559
        my $biblio = $builder->build_sample_biblio;
560
561
        my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
562
        $mock->mock( 'enqueue', sub {
563
            my ( $self, $args ) = @_;
564
            is_deeply(
565
                $args->{biblio_ids},
566
                [ $biblio->id ],
567
                '->cancel triggers a holds queue update for the related biblio'
568
            );
569
        } );
570
571
        $builder->build_object(
572
            {
573
                class => 'Koha::Holds',
574
                value => {
575
                    biblionumber   => $biblio->id,
576
                }
577
            }
578
        )->cancel;
579
580
        # If the skip_holds_queue param is not honoured, then test count will fail.
581
        $builder->build_object(
582
            {
583
                class => 'Koha::Holds',
584
                value => {
585
                    biblionumber   => $biblio->id,
586
                }
587
            }
588
        )->cancel({ skip_holds_queue => 1 });
589
    };
590
591
    $schema->storage->txn_rollback;
592
};
593
594
subtest 'suspend_hold() and resume() tests' => sub {
595
596
    plan tests => 2;
597
598
    $schema->storage->txn_begin;
599
600
    my $biblio = $builder->build_sample_biblio;
601
    my $action;
602
603
    my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
604
    $mock->mock( 'enqueue', sub {
605
        my ( $self, $args ) = @_;
606
        is_deeply(
607
            $args->{biblio_ids},
608
            [ $biblio->id ],
609
            "->$action triggers a holds queue update for the related biblio"
610
        );
611
    } );
612
613
    my $hold = $builder->build_object(
614
        {
615
            class => 'Koha::Holds',
616
            value => {
617
                biblionumber => $biblio->id,
618
            }
619
        }
620
    );
621
622
    $action = 'suspend_hold';
623
    $hold->suspend_hold;
624
625
    $action = 'resume';
626
    $hold->resume;
627
529
    $schema->storage->txn_rollback;
628
    $schema->storage->txn_rollback;
530
};
629
};
(-)a/t/db_dependent/Reserves.t (-2 / +32 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 69;
20
use Test::More tests => 70;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 1397-1399 subtest 'IsAvailableForItemLevelRequest() tests' => sub { Link Here
1397
1397
1398
    $schema->storage->txn_rollback;
1398
    $schema->storage->txn_rollback;
1399
};
1399
};
1400
- 
1400
1401
subtest 'AddReserve() tests' => sub {
1402
1403
    plan tests => 1;
1404
1405
    $schema->storage->txn_begin;
1406
1407
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
1408
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
1409
    my $biblio  = $builder->build_sample_biblio;
1410
1411
    my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
1412
    $mock->mock( 'enqueue', sub {
1413
        my ( $self, $args ) = @_;
1414
        is_deeply(
1415
            $args->{biblio_ids},
1416
            [ $biblio->id ],
1417
            "AddReserve triggers a holds queue update for the related biblio"
1418
        );
1419
    } );
1420
1421
    AddReserve(
1422
        {
1423
            branchcode     => $library->branchcode,
1424
            borrowernumber => $patron->id,
1425
            biblionumber   => $biblio->id,
1426
        }
1427
    );
1428
1429
    $schema->storage->txn_rollback;
1430
};

Return to bug 29346