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 (-2 / +55 lines)
Lines 19-32 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
23
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::Libraries;
30
use Koha::Libraries;
31
use Koha::Old::Holds;
30
32
31
my $schema  = Koha::Database->new->schema;
33
my $schema  = Koha::Database->new->schema;
32
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
Lines 202-204 subtest 'is_pickup_location_valid() tests' => sub { Link Here
202
204
203
    $schema->storage->txn_rollback;
205
    $schema->storage->txn_rollback;
204
};
206
};
205
- 
207
208
subtest 'cancel() tests' => sub {
209
210
    plan tests => 3;
211
212
    $schema->storage->txn_begin;
213
214
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
215
216
    # reduce the tests noise
217
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
218
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',
219
        undef );
220
221
    # 0 == keep forever
222
    $patron->privacy(0)->store;
223
    my $hold = $builder->build_object(
224
        {
225
            class => 'Koha::Holds',
226
            value => { borrowernumber => $patron->id, status => undef }
227
        }
228
    );
229
    $hold->cancel();
230
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
231
        $patron->borrowernumber, 'Patron link is kept' );
232
233
    # 1 == "default", meaning it is not protected from removal
234
    $patron->privacy(1)->store;
235
    $hold = $builder->build_object(
236
        {
237
            class => 'Koha::Holds',
238
            value => { borrowernumber => $patron->id, status => undef }
239
        }
240
    );
241
    $hold->cancel();
242
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
243
        $patron->borrowernumber, 'Patron link is kept' );
244
245
    # 2 == delete immediately
246
    $patron->privacy(2)->store;
247
    $hold = $builder->build_object(
248
        {
249
            class => 'Koha::Holds',
250
            value => { borrowernumber => $patron->id, status => undef }
251
        }
252
    );
253
    $hold->cancel();
254
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
255
        undef, 'Patron link is deleted immediately' );
256
257
    $schema->storage->txn_rollback;
258
};

Return to bug 29525