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

(-)a/Koha/Exceptions/Patron.pm (+4 lines)
Lines 15-20 use Exception::Class ( Link Here
15
        isa         => 'Koha::Exceptions::Patron',
15
        isa         => 'Koha::Exceptions::Patron',
16
        description => "Deleting patron failed"
16
        description => "Deleting patron failed"
17
    },
17
    },
18
    'Koha::Exceptions::Patron::FailedAnonymizing' => {
19
        isa         => 'Koha::Exceptions::Patron',
20
        description => "Anonymizing patron reading history failed"
21
    },
18
    'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron' => {
22
    'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron' => {
19
        isa         => 'Koha::Exceptions::Patron',
23
        isa         => 'Koha::Exceptions::Patron',
20
        description => "Deleting patron failed, AnonymousPatron is not deleteable"
24
        description => "Deleting patron failed, AnonymousPatron is not deleteable"
(-)a/Koha/Patron.pm (+16 lines)
Lines 298-303 sub store { Link Here
298
                    $self->userid($stored_userid);
298
                    $self->userid($stored_userid);
299
                }
299
                }
300
300
301
                # If a borrower has set their privacy to never we should immediately anonymize
302
                # their checkouts
303
                if( $self->privacy() == 2 && $self_from_storage->privacy() != 2 ){
304
                    try{
305
                        my $schema = Koha::Database->new()->schema();
306
                        $schema->txn_do(
307
                            sub { $self->old_checkouts->anonymize; }
308
                        );
309
                    }
310
                    catch {
311
                        Koha::Exceptions::Patron::FailedAnonymizing->throw(
312
                            error => @_
313
                        );
314
                    };
315
                }
316
301
                # Password must be updated using $self->set_password
317
                # Password must be updated using $self->set_password
302
                $self->password($self_from_storage->password);
318
                $self->password($self_from_storage->password);
303
319
(-)a/t/db_dependent/Koha/Patron.t (-2 / +33 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 20;
22
use Test::More tests => 21;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 1398-1400 subtest 'get_savings tests' => sub { Link Here
1398
1398
1399
    $schema->storage->txn_rollback;
1399
    $schema->storage->txn_rollback;
1400
};
1400
};
1401
- 
1401
1402
subtest 'update privacy tests' => sub {
1403
1404
    plan tests => 5;
1405
1406
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { privacy => 1 } });
1407
1408
    my $old_checkout = $builder->build_object({ class => 'Koha::Old::Checkouts', value => { borrowernumber => $patron->id } });
1409
1410
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '0' );
1411
1412
    $patron->privacy(2); #set to never
1413
1414
    throws_ok{ $patron->store } 'Koha::Exceptions::Patron::FailedAnonymizing', 'We throw an exception when anonymizing fails';
1415
1416
    $old_checkout->discard_changes; #refresh from db
1417
    $patron->discard_changes;
1418
1419
    is( $old_checkout->borrowernumber, $patron->id, "When anonymizing fails, we don't clear the checkouts");
1420
    is( $patron->privacy(), 1, "When anonymizing fails, we don't chaneg the privacy");
1421
1422
    my $anon_patron = $builder->build_object({ class => 'Koha::Patrons'});
1423
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anon_patron->id );
1424
1425
    $patron->privacy(2)->store(); #set to never
1426
1427
    $old_checkout->discard_changes; #refresh from db
1428
    $patron->discard_changes;
1429
1430
    is( $old_checkout->borrowernumber, $anon_patron->id, "Checkout is successfully anonymized");
1431
    is( $patron->privacy(), 2, "Patron privacy is successfully updated");
1432
};

Return to bug 33229