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

(-)a/Koha/Statistic.pm (-1 / +9 lines)
Lines 149-155 Generate a pesudonymized version of the statistic. Link Here
149
sub pseudonymize {
149
sub pseudonymize {
150
    my ($self) = @_;
150
    my ($self) = @_;
151
151
152
    return unless ( $self->borrowernumber && grep { $_ eq $self->type } qw(renew issue return onsite_checkout) );
152
    return unless ( $self->borrowernumber && grep { $_ eq $self->type } @Koha::Statistic::pseudonymization_types );
153
153
154
    # FIXME When getting the object from svc/renewal we get a DateTime object
154
    # FIXME When getting the object from svc/renewal we get a DateTime object
155
    # normally we just fetch from DB to clear this, but statistics has no primary key
155
    # normally we just fetch from DB to clear this, but statistics has no primary key
Lines 161-166 sub pseudonymize { Link Here
161
161
162
}
162
}
163
163
164
=head2 Pseudonymization types
165
166
=head3 @pseudonymization_types
167
168
=cut
169
170
our @pseudonymization_types = qw(renew issue return onsite_checkout);
171
164
=head2 Internal methods
172
=head2 Internal methods
165
173
166
=head3 _type
174
=head3 _type
(-)a/misc/cronjobs/cleanup_database.pl (-6 / +27 lines)
Lines 54-64 use Koha::Old::Patrons; Link Here
54
use Koha::Patron::Debarments qw( DelDebarment );
54
use Koha::Patron::Debarments qw( DelDebarment );
55
use Koha::Patron::Messages;
55
use Koha::Patron::Messages;
56
use Koha::PseudonymizedTransactions;
56
use Koha::PseudonymizedTransactions;
57
use Koha::Statistics;
57
use Koha::UploadedFiles;
58
use Koha::UploadedFiles;
58
59
59
sub usage {
60
sub usage {
60
    print STDERR <<USAGE;
61
    print STDERR <<USAGE;
61
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] [--labels DAYS] [--cards DAYS] [--bg-days DAYS [--bg-type TYPE] ] [--edifact-messages DAYS]
62
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--statistics-type TYPE] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] [--labels DAYS] [--cards DAYS] [--bg-days DAYS [--bg-type TYPE] ] [--edifact-messages DAYS]
62
63
63
   -h --help          prints this help message, and exits, ignoring all
64
   -h --help          prints this help message, and exits, ignoring all
64
                      other options
65
                      other options
Lines 107-112 Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] Link Here
107
   --oauth-tokens     Delete expired OAuth2 tokens
108
   --oauth-tokens     Delete expired OAuth2 tokens
108
   --statistics DAYS       Purge statistics entries more than DAYS days old.
109
   --statistics DAYS       Purge statistics entries more than DAYS days old.
109
                           This table is used to build reports, make sure you are aware of the consequences of this before using it!
110
                           This table is used to build reports, make sure you are aware of the consequences of this before using it!
111
   --statistics-type TYPES  What type of statistics to purge. Will purge all types if parameter is omitted. Repeatable.
112
   --statistics-type-pseudo Purges statistic types of "@Koha::Statistic::pseudonymization_types", unless more types are defined
113
                            with --statistics-type.
110
   --deleted-catalog  DAYS Purge catalog records deleted more then DAYS days ago
114
   --deleted-catalog  DAYS Purge catalog records deleted more then DAYS days ago
111
                           (from tables deleteditems, deletedbiblioitems, deletedbiblio_metadata and deletedbiblio).
115
                           (from tables deleteditems, deletedbiblioitems, deletedbiblio_metadata and deletedbiblio).
112
   --deleted-patrons DAYS  Purge patrons deleted more than DAYS days ago.
116
   --deleted-patrons DAYS  Purge patrons deleted more than DAYS days ago.
Lines 155-160 my $temp_uploads_days; Link Here
155
my $uploads_missing;
159
my $uploads_missing;
156
my $oauth_tokens;
160
my $oauth_tokens;
157
my $pStatistics;
161
my $pStatistics;
162
my @statistics_types;
163
my $statistics_type_pseudo;
158
my $pDeletedCatalog;
164
my $pDeletedCatalog;
159
my $pDeletedPatrons;
165
my $pDeletedPatrons;
160
my $pOldIssues;
166
my $pOldIssues;
Lines 204-209 GetOptions( Link Here
204
    'uploads-missing:i'          => \$uploads_missing,
210
    'uploads-missing:i'          => \$uploads_missing,
205
    'oauth-tokens'               => \$oauth_tokens,
211
    'oauth-tokens'               => \$oauth_tokens,
206
    'statistics:i'               => \$pStatistics,
212
    'statistics:i'               => \$pStatistics,
213
    'statistics-type:s'          => \@statistics_types,
214
    'statistics-type-pseudo:i'   => \$statistics_type_pseudo,
207
    'deleted-catalog:i'          => \$pDeletedCatalog,
215
    'deleted-catalog:i'          => \$pDeletedCatalog,
208
    'deleted-patrons:i'          => \$pDeletedPatrons,
216
    'deleted-patrons:i'          => \$pDeletedPatrons,
209
    'old-issues:i'               => \$pOldIssues,
217
    'old-issues:i'               => \$pOldIssues,
Lines 234-239 $jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) Link Here
234
@jobs_types       = (DEFAULT_JOBS_PURGETYPES)       if $jobs_days                 && @jobs_types == 0;
242
@jobs_types       = (DEFAULT_JOBS_PURGETYPES)       if $jobs_days                 && @jobs_types == 0;
235
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS   if defined($edifact_msg_days) && $edifact_msg_days == 0;
243
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS   if defined($edifact_msg_days) && $edifact_msg_days == 0;
236
244
245
@statistics_types = (@statistics_types, @Koha::Statistic::pseudonymization_types) if defined($statistics_type_pseudo);
246
@statistics_types = keys %{{ map { $_, 1 } @statistics_types }}; # remove duplicate types
247
237
# Choose the number of days at which to purge unaccepted list invites:
248
# Choose the number of days at which to purge unaccepted list invites:
238
# - DAYS defined in the list-invites parameter is prioritised first
249
# - DAYS defined in the list-invites parameter is prioritised first
239
# - PurgeListShareInvitesOlderThan system preference is prioritised second
250
# - PurgeListShareInvitesOlderThan system preference is prioritised second
Lines 603-613 if ($oauth_tokens) { Link Here
603
}
614
}
604
615
605
if ($pStatistics) {
616
if ($pStatistics) {
606
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
617
    print "Purging statistics older than $pStatistics days" if $verbose;
607
    my $statistics =
618
    my $statistics_search_params = {};
608
        Koha::Statistics->filter_by_last_update( { timestamp_column_name => 'datetime', days => $pStatistics } );
619
609
    my $count = $statistics->count;
620
    if ( scalar(@statistics_types) ) {
610
    $statistics->delete if $confirm;
621
        print " with types \"".join(',', @statistics_types)."\".\n" if $verbose;
622
        $statistics_search_params->{type} = \@statistics_types;
623
624
    }
625
    print "\n" if $verbose;
626
627
    my $statistics = Koha::Statistics->search( $statistics_search_params );
628
    my $filtered_statistics =
629
        $statistics->filter_by_last_update( { timestamp_column_name => 'datetime', days => $pStatistics } );
630
    my $count = $filtered_statistics->count;
631
    $filtered_statistics->delete if $confirm;
611
    if ($verbose) {
632
    if ($verbose) {
612
        say $confirm
633
        say $confirm
613
            ? sprintf( "Done with purging %d statistics",       $count )
634
            ? sprintf( "Done with purging %d statistics",       $count )
(-)a/t/db_dependent/Koha/Statistic.t (-5 / +3 lines)
Lines 61-68 subtest 'new() tests' => sub { Link Here
61
61
62
subtest 'pseudonymize() tests' => sub {
62
subtest 'pseudonymize() tests' => sub {
63
63
64
    my @pseudonymization_types = qw(renew issue return onsite_checkout);
64
    plan tests => scalar(@Koha::Statistic::pseudonymization_types) + 2;
65
    plan tests => scalar(@pseudonymization_types) + 2;
66
65
67
    $schema->storage->txn_begin;
66
    $schema->storage->txn_begin;
68
67
Lines 73-82 subtest 'pseudonymize() tests' => sub { Link Here
73
72
74
    my @statistics = ();
73
    my @statistics = ();
75
74
76
    ok( scalar(@pseudonymization_types) > 0, 'some pseudonymization_types are defined' );
75
    ok( scalar(@Koha::Statistic::pseudonymization_types) > 0, 'some pseudonymization_types are defined' );
77
76
78
    my $sub_days = 0;    # TestBuilder does not handle many rows of Koha::Statistics very intuitively
77
    my $sub_days = 0;    # TestBuilder does not handle many rows of Koha::Statistics very intuitively
79
    foreach my $type (@pseudonymization_types) {
78
    foreach my $type (@Koha::Statistic::pseudonymization_types) {
80
        push(
79
        push(
81
            @statistics,
80
            @statistics,
82
            $builder->build_object(
81
            $builder->build_object(
83
- 

Return to bug 32440