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

(-)a/Koha/Hold.pm (-1 / +7 lines)
Lines 517-522 sub cancel { Link Here
517
    my ( $self, $params ) = @_;
517
    my ( $self, $params ) = @_;
518
    $self->_result->result_source->schema->txn_do(
518
    $self->_result->result_source->schema->txn_do(
519
        sub {
519
        sub {
520
            my $patron = $self->patron;
521
520
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
522
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
521
            $self->priority(0);
523
            $self->priority(0);
522
            $self->cancellation_reason( $params->{cancellation_reason} );
524
            $self->cancellation_reason( $params->{cancellation_reason} );
Lines 550-556 sub cancel { Link Here
550
                }
552
                }
551
            }
553
            }
552
554
553
            $self->_move_to_old;
555
            my $old_me = $self->_move_to_old;
556
            # anonymize if required
557
            $old_me->anonymize
558
                if $patron->privacy == 2;
559
554
            $self->SUPER::delete(); # Do not add a DELETE log
560
            $self->SUPER::delete(); # Do not add a DELETE log
555
561
556
            # now fix the priority on the others....
562
            # now fix the priority on the others....
(-)a/t/db_dependent/Koha/Hold.t (-1 / +72 lines)
Lines 24-35 use Test::More tests => 5; Link Here
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
27
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
28
use t::lib::Mocks;
29
use t::lib::Mocks;
29
30
30
use Koha::ActionLogs;
31
use Koha::ActionLogs;
31
use Koha::Holds;
32
use Koha::Holds;
32
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Old::Holds;
33
35
34
my $schema  = Koha::Database->new->schema;
36
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
37
my $builder = t::lib::TestBuilder->new;
Lines 382-384 subtest 'is_pickup_location_valid() tests' => sub { Link Here
382
384
383
    $schema->storage->txn_rollback;
385
    $schema->storage->txn_rollback;
384
};
386
};
385
- 
387
388
subtest 'cancel() tests' => sub {
389
390
    plan tests => 4;
391
392
    $schema->storage->txn_begin;
393
394
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
395
396
    # reduce the tests noise
397
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
398
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',
399
        undef );
400
401
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
402
403
    # 0 == keep forever
404
    $patron->privacy(0)->store;
405
    my $hold = $builder->build_object(
406
        {
407
            class => 'Koha::Holds',
408
            value => { borrowernumber => $patron->id, status => undef }
409
        }
410
    );
411
    $hold->cancel();
412
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
413
        $patron->borrowernumber, 'Patron link is kept' );
414
415
    # 1 == "default", meaning it is not protected from removal
416
    $patron->privacy(1)->store;
417
    $hold = $builder->build_object(
418
        {
419
            class => 'Koha::Holds',
420
            value => { borrowernumber => $patron->id, status => undef }
421
        }
422
    );
423
    $hold->cancel();
424
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
425
        $patron->borrowernumber, 'Patron link is kept' );
426
427
    # 2 == delete immediately
428
    $patron->privacy(2)->store;
429
    $hold = $builder->build_object(
430
        {
431
            class => 'Koha::Holds',
432
            value => { borrowernumber => $patron->id, status => undef }
433
        }
434
    );
435
    $hold->cancel();
436
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
437
        undef, 'Patron link is deleted immediately' );
438
439
    my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
440
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
441
442
    $hold = $builder->build_object(
443
        {
444
            class => 'Koha::Holds',
445
            value => { borrowernumber => $patron->id, status => undef }
446
        }
447
    );
448
    $hold->cancel();
449
    is(
450
        Koha::Old::Holds->find( $hold->id )->borrowernumber,
451
        $anonymous_patron->id,
452
        'Patron link is set to the configured anonymous patron immediately'
453
    );
454
455
    $schema->storage->txn_rollback;
456
};

Return to bug 29525