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

(-)a/misc/cronjobs/batch_anonymise.pl (-5 / +22 lines)
Lines 17-31 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use Koha::Script -cron;
22
use Koha::Script -cron;
23
24
use C4::Context;
24
use C4::Context;
25
use C4::Log qw( cronlogaction );
26
27
use Koha::Database;
28
use Koha::DateUtils qw(dt_from_string);
25
use Koha::Patrons;
29
use Koha::Patrons;
30
26
use Date::Calc qw( Add_Delta_Days Today );
31
use Date::Calc qw( Add_Delta_Days Today );
27
use Getopt::Long qw( GetOptions );
32
use Getopt::Long qw( GetOptions );
28
use C4::Log qw( cronlogaction );
29
33
30
sub usage {
34
sub usage {
31
    print STDERR <<USAGE;
35
    print STDERR <<USAGE;
Lines 58-69 if ( !$days ) { Link Here
58
62
59
cronlogaction();
63
cronlogaction();
60
64
65
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
66
61
my ($year,$month,$day) = Today();
67
my ($year,$month,$day) = Today();
62
my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days);
68
my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days);
63
my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday;
69
my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday;
64
$verbose and print "Checkouts before $formatdate will be anonymised.\n";
70
$verbose and print "Checkouts and holds before $formatdate will be anonymised.\n";
65
71
66
my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $formatdate } )->anonymise_issue_history( { before => $formatdate } );
72
my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $formatdate } )->anonymise_issue_history( { before => $formatdate } );
67
$verbose and print int($rows) . " checkouts anonymised.\n";
73
$verbose and print int($rows) . " checkouts anonymised.\n";
68
74
75
$rows = Koha::Old::Holds->filter_by_anonymizable->search(
76
    {
77
        timestamp => {
78
            '<' => $dtf->format_datetime(
79
                dt_from_string()->subtract( days => $days )
80
            )
81
        }
82
    }
83
)->anonymize;
84
85
$verbose and print int($rows) . " holds anonymised.\n";
86
69
exit(0);
87
exit(0);
70
- 

Return to bug 29525