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-34 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
29
29
use Koha::ActionLogs;
30
use Koha::ActionLogs;
30
use Koha::Holds;
31
use Koha::Holds;
31
use Koha::Libraries;
32
use Koha::Libraries;
33
use Koha::Old::Holds;
32
34
33
my $schema  = Koha::Database->new->schema;
35
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
36
my $builder = t::lib::TestBuilder->new;
Lines 335-337 subtest 'is_pickup_location_valid() tests' => sub { Link Here
335
337
336
    $schema->storage->txn_rollback;
338
    $schema->storage->txn_rollback;
337
};
339
};
338
- 
340
341
subtest 'cancel() tests' => sub {
342
343
    plan tests => 4;
344
345
    $schema->storage->txn_begin;
346
347
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
348
349
    # reduce the tests noise
350
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
351
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',
352
        undef );
353
354
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
355
356
    # 0 == keep forever
357
    $patron->privacy(0)->store;
358
    my $hold = $builder->build_object(
359
        {
360
            class => 'Koha::Holds',
361
            value => { borrowernumber => $patron->id, status => undef }
362
        }
363
    );
364
    $hold->cancel();
365
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
366
        $patron->borrowernumber, 'Patron link is kept' );
367
368
    # 1 == "default", meaning it is not protected from removal
369
    $patron->privacy(1)->store;
370
    $hold = $builder->build_object(
371
        {
372
            class => 'Koha::Holds',
373
            value => { borrowernumber => $patron->id, status => undef }
374
        }
375
    );
376
    $hold->cancel();
377
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
378
        $patron->borrowernumber, 'Patron link is kept' );
379
380
    # 2 == delete immediately
381
    $patron->privacy(2)->store;
382
    $hold = $builder->build_object(
383
        {
384
            class => 'Koha::Holds',
385
            value => { borrowernumber => $patron->id, status => undef }
386
        }
387
    );
388
    $hold->cancel();
389
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
390
        undef, 'Patron link is deleted immediately' );
391
392
    my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
393
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
394
395
    $hold = $builder->build_object(
396
        {
397
            class => 'Koha::Holds',
398
            value => { borrowernumber => $patron->id, status => undef }
399
        }
400
    );
401
    $hold->cancel();
402
    is(
403
        Koha::Old::Holds->find( $hold->id )->borrowernumber,
404
        $anonymous_patron->id,
405
        'Patron link is set to the configured anonymous patron immediately'
406
    );
407
408
    $schema->storage->txn_rollback;
409
};

Return to bug 29525