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

(-)a/Koha/Hold.pm (-1 / +7 lines)
Lines 511-516 sub cancel { Link Here
511
    my ( $self, $params ) = @_;
511
    my ( $self, $params ) = @_;
512
    $self->_result->result_source->schema->txn_do(
512
    $self->_result->result_source->schema->txn_do(
513
        sub {
513
        sub {
514
            my $patron = $self->patron;
515
514
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
516
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
515
            $self->priority(0);
517
            $self->priority(0);
516
            $self->cancellation_reason( $params->{cancellation_reason} );
518
            $self->cancellation_reason( $params->{cancellation_reason} );
Lines 544-550 sub cancel { Link Here
544
                }
546
                }
545
            }
547
            }
546
548
547
            $self->_move_to_old;
549
            my $old_me = $self->_move_to_old;
550
            # anonymize if required
551
            $old_me->anonymize
552
                if $patron->privacy == 2;
553
548
            $self->SUPER::delete(); # Do not add a DELETE log
554
            $self->SUPER::delete(); # Do not add a DELETE log
549
555
550
            # now fix the priority on the others....
556
            # 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 336-338 subtest 'is_pickup_location_valid() tests' => sub { Link Here
336
338
337
    $schema->storage->txn_rollback;
339
    $schema->storage->txn_rollback;
338
};
340
};
339
- 
341
342
subtest 'cancel() tests' => sub {
343
344
    plan tests => 4;
345
346
    $schema->storage->txn_begin;
347
348
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
349
350
    # reduce the tests noise
351
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
352
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',
353
        undef );
354
355
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
356
357
    # 0 == keep forever
358
    $patron->privacy(0)->store;
359
    my $hold = $builder->build_object(
360
        {
361
            class => 'Koha::Holds',
362
            value => { borrowernumber => $patron->id, status => undef }
363
        }
364
    );
365
    $hold->cancel();
366
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
367
        $patron->borrowernumber, 'Patron link is kept' );
368
369
    # 1 == "default", meaning it is not protected from removal
370
    $patron->privacy(1)->store;
371
    $hold = $builder->build_object(
372
        {
373
            class => 'Koha::Holds',
374
            value => { borrowernumber => $patron->id, status => undef }
375
        }
376
    );
377
    $hold->cancel();
378
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
379
        $patron->borrowernumber, 'Patron link is kept' );
380
381
    # 2 == delete immediately
382
    $patron->privacy(2)->store;
383
    $hold = $builder->build_object(
384
        {
385
            class => 'Koha::Holds',
386
            value => { borrowernumber => $patron->id, status => undef }
387
        }
388
    );
389
    $hold->cancel();
390
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
391
        undef, 'Patron link is deleted immediately' );
392
393
    my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
394
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
395
396
    $hold = $builder->build_object(
397
        {
398
            class => 'Koha::Holds',
399
            value => { borrowernumber => $patron->id, status => undef }
400
        }
401
    );
402
    $hold->cancel();
403
    is(
404
        Koha::Old::Holds->find( $hold->id )->borrowernumber,
405
        $anonymous_patron->id,
406
        'Patron link is set to the configured anonymous patron immediately'
407
    );
408
409
    $schema->storage->txn_rollback;
410
};

Return to bug 29525