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

(-)a/Koha/Anonymized/Transaction.pm (+6 lines)
Lines 42-47 sub new_from_statistic { Link Here
42
        hashed_borrowernumber => Koha::Anonymized->get_hash($statistic->borrowernumber),
42
        hashed_borrowernumber => Koha::Anonymized->get_hash($statistic->borrowernumber),
43
    };
43
    };
44
44
45
    # In case the patron does not exist yet in the anonymized_borrowers table
46
    unless ( Koha::Anonymized::Patrons->find($values->{hashed_borrowernumber}) ) {
47
        my $patron = Koha::Patrons->find($statistic->borrowernumber);
48
        Koha::Anonymized::Patron->new_from_patron($patron)->store;
49
    }
50
45
    my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || '';
51
    my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || '';
46
52
47
    if ( grep { $_ eq 'branchcode' } @fields_to_copy ) {
53
    if ( grep { $_ eq 'branchcode' } @fields_to_copy ) {
(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 343-353 sub store { Link Here
343
            }
343
            }
344
344
345
            if ( C4::Context->preference('Pseudonymization') ) {
345
            if ( C4::Context->preference('Pseudonymization') ) {
346
                unless ( $in_storage ) {
346
                my $anonymized;
347
                    Koha::Anonymized::Patron->new_from_patron($self)->store;
347
                if ( $in_storage ) {
348
                } else {
348
                    $anonymized = Koha::Anonymized::Patrons->find_from_borrowernumber($self->borrowernumber);
349
                    Koha::Anonymized::Patrons->find_from_borrowernumber($self->borrowernumber)->update_from_patron($self)->store;
349
                    $anonymized->update_from_patron($self)->store if $anonymized;
350
                }
350
                }
351
352
                # If not set at this point, either it's a new patron
353
                # or the setting has been turned on after the patron has been created
354
                $anonymized = Koha::Anonymized::Patron->new_from_patron($self) unless $anonymized;
355
356
                $anonymized->store;
351
            }
357
            }
352
358
353
        }
359
        }
(-)a/t/db_dependent/Koha/Pseudonymization.t (-2 / +26 lines)
Lines 63-69 subtest 'Config does not exist' => sub { Link Here
63
63
64
subtest 'Koha::Anonymized::Patrons tests' => sub {
64
subtest 'Koha::Anonymized::Patrons tests' => sub {
65
65
66
    plan tests => 9;
66
    plan tests => 10;
67
67
68
    $schema->storage->txn_begin;
68
    $schema->storage->txn_begin;
69
69
Lines 98-103 subtest 'Koha::Anonymized::Patrons tests' => sub { Link Here
98
    is( $patron->sort1, "another sort1", "correctly updated" );
98
    is( $patron->sort1, "another sort1", "correctly updated" );
99
    $patron->delete;
99
    $patron->delete;
100
100
101
    subtest 'Patron was created before the Pseudonymization was actived' => sub {
102
103
        plan tests => 2;
104
105
        t::lib::Mocks::mock_preference( 'Pseudonymization', 0 );
106
        my $patron = Koha::Patron->new($patron_info)->store;
107
        $patron->discard_changes;
108
109
        t::lib::Mocks::mock_preference( 'Pseudonymization', 1 );
110
        $patron->sort1("another sort1")->store;
111
        $anonymized = Koha::Anonymized::Patrons->find_from_borrowernumber( $patron->borrowernumber );
112
        is( $anonymized->sort1, "another sort1", "correctly updated" );
113
        $anonymized->delete;
114
115
        my $item = $builder->build_sample_item;
116
        t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
117
        AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
118
        AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
119
        $anonymized = Koha::Anonymized::Transactions->search( { itemnumber => $item->itemnumber } )->next;
120
        like( $anonymized->hashed_borrowernumber,
121
            qr{^\$2a\$08\$}, "The hashed_borrowernumber has been created (and so the corresponding anonymized_borrowers entry)" );
122
123
        $patron->delete;
124
    };
125
101
    $schema->storage->txn_rollback;
126
    $schema->storage->txn_rollback;
102
};
127
};
103
128
104
- 

Return to bug 24151