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

(-)a/Koha/Patrons.pm (-4 / +8 lines)
Lines 184-197 sub article_requests_finished { Link Here
184
184
185
=head3 search_patrons_to_anonymise
185
=head3 search_patrons_to_anonymise
186
186
187
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( $date );
187
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
188
188
189
This method returns all patrons who has an issue history older than a given date.
189
This method returns all patrons who has an issue history older than a given date.
190
190
191
=cut
191
=cut
192
192
193
sub search_patrons_to_anonymise {
193
sub search_patrons_to_anonymise {
194
    my ( $class, $older_than_date, $library ) = @_;
194
    my ( $class, $params ) = @_;
195
    my $older_than_date = $params->{before};
196
    my $library         = $params->{library};
195
    $older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string;
197
    $older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string;
196
    $library ||=
198
    $library ||=
197
      ( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} )
199
      ( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} )
Lines 214-220 sub search_patrons_to_anonymise { Link Here
214
216
215
=head3 anonymise_issue_history
217
=head3 anonymise_issue_history
216
218
217
    Koha::Patrons->search->anonymise_issue_history( $older_than_date );
219
    Koha::Patrons->search->anonymise_issue_history( { before => $older_than_date } );
218
220
219
Anonymise issue history (old_issues) for all patrons older than the given date.
221
Anonymise issue history (old_issues) for all patrons older than the given date.
220
To make sure all the conditions are met, the caller has the responsability to
222
To make sure all the conditions are met, the caller has the responsability to
Lines 223-229 call search_patrons_to_anonymise to filter the Koha::Patrons set Link Here
223
=cut
225
=cut
224
226
225
sub anonymise_issue_history {
227
sub anonymise_issue_history {
226
    my ( $self, $older_than_date ) = @_;
228
    my ( $self, $params ) = @_;
229
230
    my $older_than_date = $params->{before};
227
231
228
    return unless $older_than_date;
232
    return unless $older_than_date;
229
    $older_than_date = dt_from_string $older_than_date;
233
    $older_than_date = dt_from_string $older_than_date;
(-)a/misc/cronjobs/batch_anonymise.pl (-1 / +1 lines)
Lines 74-80 my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days); Link Here
74
my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday;
74
my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday;
75
$verbose and print "Checkouts before $formatdate will be anonymised.\n";
75
$verbose and print "Checkouts before $formatdate will be anonymised.\n";
76
76
77
my $rows = Koha::Patrons->search_patrons_to_anonymise( $formatdate )->anonymise_issue_history( $formatdate );
77
my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $formatdate } )->anonymise_issue_history( { before => $formatdate } );
78
$verbose and print int($rows) . " checkouts anonymised.\n";
78
$verbose and print int($rows) . " checkouts anonymised.\n";
79
79
80
exit(0);
80
exit(0);
(-)a/opac/opac-privacy.pl (-1 / +1 lines)
Lines 63-69 elsif ( $op eq "delete_record" ) { Link Here
63
    # uses a hardcoded date ridiculously far in the future
63
    # uses a hardcoded date ridiculously far in the future
64
64
65
    my $rows = eval {
65
    my $rows = eval {
66
        Koha::Patrons->search({ 'me.borrowernumber' => $borrowernumber })->anonymise_issue_history( '2999-12-12' );
66
        Koha::Patrons->search({ 'me.borrowernumber' => $borrowernumber })->anonymise_issue_history( { before => '2999-12-12' } );
67
    };
67
    };
68
    $rows = $@ ? 0 : int($rows);
68
    $rows = $@ ? 0 : int($rows);
69
    $template->param( 'deleted' => $rows );
69
    $template->param( 'deleted' => $rows );
(-)a/t/db_dependent/Koha/Patrons.t (-5 / +5 lines)
Lines 716-725 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
716
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
716
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
717
        is( $returned, 1, 'The item should have been returned' );
717
        is( $returned, 1, 'The item should have been returned' );
718
718
719
        my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11' )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
719
        my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
720
        is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' );
720
        is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' );
721
721
722
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11');
722
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
723
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
723
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
724
724
725
        my $dbh = C4::Context->dbh;
725
        my $dbh = C4::Context->dbh;
Lines 758-764 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
758
758
759
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
759
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
760
        is( $returned, 1, 'The item should have been returned' );
760
        is( $returned, 1, 'The item should have been returned' );
761
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11');
761
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
762
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' );
762
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' );
763
763
764
        my $dbh = C4::Context->dbh;
764
        my $dbh = C4::Context->dbh;
Lines 799-805 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
799
799
800
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
800
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
801
        is( $returned, 1, 'The item should have been returned' );
801
        is( $returned, 1, 'The item should have been returned' );
802
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11');
802
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
803
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
803
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
804
804
805
        my $dbh = C4::Context->dbh;
805
        my $dbh = C4::Context->dbh;
Lines 836-842 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
836
        );
836
        );
837
837
838
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
838
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
839
        is( Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->count, 0 );
839
        is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 );
840
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
840
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
841
    };
841
    };
842
842
(-)a/tools/cleanborrowers.pl (-4 / +3 lines)
Lines 110-117 if ( $step == 2 ) { Link Here
110
    my $patrons_to_anonymize =
110
    my $patrons_to_anonymize =
111
        $checkboxes{issue}
111
        $checkboxes{issue}
112
      ? $branch eq '*'
112
      ? $branch eq '*'
113
          ? Koha::Patrons->search_patrons_to_anonymise($last_issue_date)
113
          ? Koha::Patrons->search_patrons_to_anonymise( { before => $last_issue_date } )
114
          : Koha::Patrons->search_patrons_to_anonymise( $last_issue_date, $branch )
114
          : Koha::Patrons->search_patrons_to_anonymise( { before => $last_issue_date, library => $branch } )
115
      : undef;
115
      : undef;
116
116
117
    $template->param(
117
    $template->param(
Lines 159-165 elsif ( $step == 3 ) { Link Here
159
    # Anonymising all members
159
    # Anonymising all members
160
    if ($do_anonym) {
160
    if ($do_anonym) {
161
        #FIXME: anonymisation errors are not handled
161
        #FIXME: anonymisation errors are not handled
162
        my $rows = Koha::Patrons->search_patrons_to_anonymise( $last_issue_date )->anonymise_issue_history( $last_issue_date );
162
        my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $last_issue_date } )->anonymise_issue_history( { before => $last_issue_date } );
163
        $template->param(
163
        $template->param(
164
            do_anonym   => $rows,
164
            do_anonym   => $rows,
165
        );
165
        );
166
- 

Return to bug 16966