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 53-63 use Koha::Old::Patrons; Link Here
53
use Koha::Patron::Debarments qw( DelDebarment );
53
use Koha::Patron::Debarments qw( DelDebarment );
54
use Koha::Patron::Messages;
54
use Koha::Patron::Messages;
55
use Koha::PseudonymizedTransactions;
55
use Koha::PseudonymizedTransactions;
56
use Koha::Statistics;
56
use Koha::UploadedFiles;
57
use Koha::UploadedFiles;
57
58
58
sub usage {
59
sub usage {
59
    print STDERR <<USAGE;
60
    print STDERR <<USAGE;
60
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]
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] [--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]
61
62
62
   -h --help          prints this help message, and exits, ignoring all
63
   -h --help          prints this help message, and exits, ignoring all
63
                      other options
64
                      other options
Lines 106-111 Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] Link Here
106
   --oauth-tokens     Delete expired OAuth2 tokens
107
   --oauth-tokens     Delete expired OAuth2 tokens
107
   --statistics DAYS       Purge statistics entries more than DAYS days old.
108
   --statistics DAYS       Purge statistics entries more than DAYS days old.
108
                           This table is used to build reports, make sure you are aware of the consequences of this before using it!
109
                           This table is used to build reports, make sure you are aware of the consequences of this before using it!
110
   --statistics-type TYPES  What type of statistics to purge. Will purge all types if parameter is omitted. Repeatable.
111
   --statistics-type-pseudo Purges statistic types of "@Koha::Statistic::pseudonymization_types", unless more types are defined
112
                            with --statistics-type.
109
   --deleted-catalog  DAYS Purge catalog records deleted more then DAYS days ago
113
   --deleted-catalog  DAYS Purge catalog records deleted more then DAYS days ago
110
                           (from tables deleteditems, deletedbiblioitems, deletedbiblio_metadata and deletedbiblio).
114
                           (from tables deleteditems, deletedbiblioitems, deletedbiblio_metadata and deletedbiblio).
111
   --deleted-patrons DAYS  Purge patrons deleted more than DAYS days ago.
115
   --deleted-patrons DAYS  Purge patrons deleted more than DAYS days ago.
Lines 154-159 my $temp_uploads_days; Link Here
154
my $uploads_missing;
158
my $uploads_missing;
155
my $oauth_tokens;
159
my $oauth_tokens;
156
my $pStatistics;
160
my $pStatistics;
161
my @statistics_types;
162
my $statistics_type_pseudo;
157
my $pDeletedCatalog;
163
my $pDeletedCatalog;
158
my $pDeletedPatrons;
164
my $pDeletedPatrons;
159
my $pOldIssues;
165
my $pOldIssues;
Lines 203-208 GetOptions( Link Here
203
    'uploads-missing:i'          => \$uploads_missing,
209
    'uploads-missing:i'          => \$uploads_missing,
204
    'oauth-tokens'               => \$oauth_tokens,
210
    'oauth-tokens'               => \$oauth_tokens,
205
    'statistics:i'               => \$pStatistics,
211
    'statistics:i'               => \$pStatistics,
212
    'statistics-type:s'          => \@statistics_types,
213
    'statistics-type-pseudo:i'   => \$statistics_type_pseudo,
206
    'deleted-catalog:i'          => \$pDeletedCatalog,
214
    'deleted-catalog:i'          => \$pDeletedCatalog,
207
    'deleted-patrons:i'          => \$pDeletedPatrons,
215
    'deleted-patrons:i'          => \$pDeletedPatrons,
208
    'old-issues:i'               => \$pOldIssues,
216
    'old-issues:i'               => \$pOldIssues,
Lines 233-238 $jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) Link Here
233
@jobs_types       = (DEFAULT_JOBS_PURGETYPES)       if $jobs_days                 && @jobs_types == 0;
241
@jobs_types       = (DEFAULT_JOBS_PURGETYPES)       if $jobs_days                 && @jobs_types == 0;
234
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS   if defined($edifact_msg_days) && $edifact_msg_days == 0;
242
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS   if defined($edifact_msg_days) && $edifact_msg_days == 0;
235
243
244
@statistics_types = (@statistics_types, @Koha::Statistic::pseudonymization_types) if defined($statistics_type_pseudo);
245
@statistics_types = keys %{{ map { $_, 1 } @statistics_types }}; # remove duplicate types
246
236
# Choose the number of days at which to purge unaccepted list invites:
247
# Choose the number of days at which to purge unaccepted list invites:
237
# - DAYS defined in the list-invites parameter is prioritised first
248
# - DAYS defined in the list-invites parameter is prioritised first
238
# - PurgeListShareInvitesOlderThan system preference is prioritised second
249
# - PurgeListShareInvitesOlderThan system preference is prioritised second
Lines 585-595 if ($oauth_tokens) { Link Here
585
}
596
}
586
597
587
if ($pStatistics) {
598
if ($pStatistics) {
588
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
599
    print "Purging statistics older than $pStatistics days" if $verbose;
589
    my $statistics =
600
    my $statistics_search_params = {};
590
        Koha::Statistics->filter_by_last_update( { timestamp_column_name => 'datetime', days => $pStatistics } );
601
591
    my $count = $statistics->count;
602
    if ( scalar(@statistics_types) ) {
592
    $statistics->delete if $confirm;
603
        print " with types \"".join(',', @statistics_types)."\".\n" if $verbose;
604
        $statistics_search_params->{type} = \@statistics_types;
605
606
    }
607
    print "\n" if $verbose;
608
609
    my $statistics = Koha::Statistics->search( $statistics_search_params );
610
    my $filtered_statistics = 
611
        $statistics->filter_by_last_update( { timestamp_column_name => 'datetime', days => $pStatistics } );
612
    my $count = $filtered_statistics->count;
613
    $filtered_statistics->delete if $confirm;
593
    if ($verbose) {
614
    if ($verbose) {
594
        say $confirm
615
        say $confirm
595
            ? sprintf( "Done with purging %d statistics",       $count )
616
            ? 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