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

(-)a/Koha/Patrons.pm (-3 / +4 lines)
Lines 204-222 sub anonymize_last_borrowers { Link Here
204
    my ( $self, $params ) = @_;
204
    my ( $self, $params ) = @_;
205
205
206
    return unless C4::Context->preference("AnonymizeLastBorrower");
206
    return unless C4::Context->preference("AnonymizeLastBorrower");
207
    return unless C4::Context->preference("AnonymousPatron");
207
    my $days = C4::Context->preference("AnonymizeLastBorrowerDays") || 0;
208
    my $days = C4::Context->preference("AnonymizeLastBorrowerDays") || 0;
208
    my ( $year, $month, $day )          = Today();
209
    my ( $year, $month, $day )          = Today();
209
    my ( $newyear, $newmonth, $newday ) = Add_Delta_Days( $year, $month, $day, (-1) * $days );
210
    my ( $newyear, $newmonth, $newday ) = Add_Delta_Days( $year, $month, $day, (-1) * $days );
210
    my $older_than_date = dt_from_string( sprintf "%4d-%02d-%02d", $newyear, $newmonth, $newday );
211
    my $older_than_date = dt_from_string( sprintf "%4d-%02d-%02d", $newyear, $newmonth, $newday );
211
212
212
    my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef;
213
    my $anonymous_patron = C4::Context->preference('AnonymousPatron');
213
214
214
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
215
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
215
    my $rs  = $self->_resultset->search(
216
    my $rs  = $self->_resultset->search(
216
        {
217
        {
217
            created_on                            => { '<'   => $dtf->format_datetime($older_than_date), },
218
            created_on                            => { '<'   => $dtf->format_datetime($older_than_date), },
218
            'items_last_borrowers.borrowernumber' => { 'not' => undef },    # Keep forever
219
            'items_last_borrowers.borrowernumber' => { 'not' => undef },               # Keep forever
219
            ( $anonymous_patron ? ( 'items_last_borrowers.borrowernumber' => { '!=' => $anonymous_patron } ) : () ),
220
            'items_last_borrowers.borrowernumber' => { '!='  => $anonymous_patron },
220
        },
221
        },
221
        {
222
        {
222
            join     => ["items_last_borrowers"],
223
            join     => ["items_last_borrowers"],
(-)a/misc/cronjobs/anonymize_last_borrowers.pl (-4 / +8 lines)
Lines 40-46 Usage: $0 [-h|--help] Link Here
40
   -v --verbose       gives a little more information
40
   -v --verbose       gives a little more information
41
   -h --help          prints this help message, and exits, ignoring all
41
   -h --help          prints this help message, and exits, ignoring all
42
                      other options
42
                      other options
43
Note: If the system preference 'AnonymousPatron' is not defined, NULL will be used.
44
USAGE
43
USAGE
45
    exit $_[0];
44
    exit $_[0];
46
}
45
}
Lines 57-69 if ($help) { Link Here
57
    usage(0);
56
    usage(0);
58
}
57
}
59
58
60
my $pref = C4::Context->preference("AnonymizeLastBorrower");
59
my $pref1 = C4::Context->preference("AnonymizeLastBorrower");
60
my $pref2 = C4::Context->preference("AnonymousPatron");
61
61
62
if ( !$pref ) {
62
if ( !$pref1 ) {
63
    print "Preference 'AnonymizeLastBorrower' must be enabled to anonymize item's last borrower\n\n";
63
    print "Preference 'AnonymizeLastBorrower' must be enabled to anonymize item's last borrower\n\n";
64
    usage(1);
64
    usage(1);
65
}
65
}
66
66
67
if ( !$pref2 ) {
68
    print "Preference 'AnonymousPatron' must be enabled to anonymize item's last borrower\n\n";
69
    usage(1);
70
}
71
67
unless ($confirm) {
72
unless ($confirm) {
68
    print STDERR "You must use the --confirm flag to run this script.\n";
73
    print STDERR "You must use the --confirm flag to run this script.\n";
69
    print STDERR "Add --confirm to actually perform the anonymization.\n";
74
    print STDERR "Add --confirm to actually perform the anonymization.\n";
70
- 

Return to bug 23260