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

(-)a/C4/Circulation.pm (-12 / +1 lines)
Lines 2359-2375 sub MarkIssueReturned { Link Here
2359
2359
2360
    my $issue_id = $issue->issue_id;
2360
    my $issue_id = $issue->issue_id;
2361
2361
2362
    my $anonymouspatron;
2363
    if ( $privacy && $privacy == 2 ) {
2364
        # The default of 0 will not work due to foreign key constraints
2365
        # The anonymisation will fail if AnonymousPatron is not a valid entry
2366
        # We need to check if the anonymous patron exist, Koha will fail loudly if it does not
2367
        # Note that a warning should appear on the about page (System information tab).
2368
        $anonymouspatron = C4::Context->preference('AnonymousPatron');
2369
        die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly."
2370
            unless Koha::Patrons->find( $anonymouspatron );
2371
    }
2372
2373
    my $schema = Koha::Database->schema;
2362
    my $schema = Koha::Database->schema;
2374
2363
2375
    # FIXME Improve the return value and handle it from callers
2364
    # FIXME Improve the return value and handle it from callers
Lines 2390-2396 sub MarkIssueReturned { Link Here
2390
2379
2391
        # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
2380
        # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
2392
        if ( $privacy && $privacy == 2) {
2381
        if ( $privacy && $privacy == 2) {
2393
            $old_checkout->borrowernumber($anonymouspatron)->store;
2382
            $old_checkout->anonymize;
2394
        }
2383
        }
2395
2384
2396
        # And finally delete the issue
2385
        # And finally delete the issue
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-4 / +8 lines)
Lines 76-82 subtest 'Failure tests' => sub { Link Here
76
76
77
subtest 'Anonymous patron tests' => sub {
77
subtest 'Anonymous patron tests' => sub {
78
78
79
    plan tests => 2;
79
    plan tests => 3;
80
80
81
    $schema->storage->txn_begin;
81
    $schema->storage->txn_begin;
82
82
Lines 99-106 subtest 'Anonymous patron tests' => sub { Link Here
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
100
100
101
    my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
101
    my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
102
    eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) };
102
103
    like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'AnonymousPatron is not set - Fatal error on anonymization' );
103
    throws_ok
104
        { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); }
105
        'Koha::Exceptions::SysPref::NotSet',
106
        'AnonymousPatron not set causes an exception';
107
108
    is( $@->syspref, 'AnonymousPatron', 'AnonymousPatron is not set - Fatal error on anonymization' );
104
    Koha::Checkouts->find( $issue->issue_id )->delete;
109
    Koha::Checkouts->find( $issue->issue_id )->delete;
105
110
106
    # Create a valid anonymous user
111
    # Create a valid anonymous user
107
- 

Return to bug 30023