|
Lines 30-35
use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30;
Link Here
|
| 30 |
use constant DEFAULT_JOBS_PURGEDAYS => 1; |
30 |
use constant DEFAULT_JOBS_PURGEDAYS => 1; |
| 31 |
use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; |
31 |
use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; |
| 32 |
use constant DEFAULT_EDIFACT_MSG_PURGEDAYS => 365; |
32 |
use constant DEFAULT_EDIFACT_MSG_PURGEDAYS => 365; |
|
|
33 |
use constant DEFAULT_LOGS_BATCHSIZE => 1000; |
| 33 |
|
34 |
|
| 34 |
use Getopt::Long qw( GetOptions ); |
35 |
use Getopt::Long qw( GetOptions ); |
| 35 |
use Try::Tiny; |
36 |
use Try::Tiny; |
|
Lines 89-94
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
Link Here
|
| 89 |
--log-action Specify which action log action entries to trim. Repeatable. |
90 |
--log-action Specify which action log action entries to trim. Repeatable. |
| 90 |
--logs DAYS purge entries from action_logs older than DAYS days. |
91 |
--logs DAYS purge entries from action_logs older than DAYS days. |
| 91 |
Defaults to 180 days if no days specified. |
92 |
Defaults to 180 days if no days specified. |
|
|
93 |
--logs-batch ROWS Delete action_logs rows in batches of ROWS. Ignored if --logs is not set. |
| 94 |
Defaults to 1000. |
| 92 |
--searchhistory DAYS purge entries from search_history older than DAYS days. |
95 |
--searchhistory DAYS purge entries from search_history older than DAYS days. |
| 93 |
Defaults to 30 days if no days specified |
96 |
Defaults to 30 days if no days specified |
| 94 |
--list-invites DAYS purge (unaccepted) list share invites older than DAYS days. |
97 |
--list-invites DAYS purge (unaccepted) list share invites older than DAYS days. |
|
Lines 178-183
my $jobs_days;
Link Here
|
| 178 |
my @jobs_types; |
181 |
my @jobs_types; |
| 179 |
my $reports; |
182 |
my $reports; |
| 180 |
my $edifact_msg_days; |
183 |
my $edifact_msg_days; |
|
|
184 |
my $logs_batch; |
| 181 |
|
185 |
|
| 182 |
my $command_line_options = join( " ", @ARGV ); |
186 |
my $command_line_options = join( " ", @ARGV ); |
| 183 |
cronlogaction( { info => $command_line_options } ); |
187 |
cronlogaction( { info => $command_line_options } ); |
|
Lines 228-233
GetOptions(
Link Here
|
| 228 |
'jobs-days:i' => \$jobs_days, |
232 |
'jobs-days:i' => \$jobs_days, |
| 229 |
'reports:i' => \$reports, |
233 |
'reports:i' => \$reports, |
| 230 |
'edifact-messages:i' => \$edifact_msg_days, |
234 |
'edifact-messages:i' => \$edifact_msg_days, |
|
|
235 |
'logs-batch:i' => \$logs_batch, |
| 231 |
) || usage(1); |
236 |
) || usage(1); |
| 232 |
|
237 |
|
| 233 |
# Use default values |
238 |
# Use default values |
|
Lines 242-247
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages)
Link Here
|
| 242 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
247 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
| 243 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
248 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
| 244 |
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; |
249 |
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; |
|
|
250 |
$logs_batch = DEFAULT_LOGS_BATCHSIZE if defined($logs_batch) && $logs_batch == 0; |
| 245 |
|
251 |
|
| 246 |
@statistics_types = ( @statistics_types, @Koha::Statistic::pseudonymization_types ) if defined($statistics_type_pseudo); |
252 |
@statistics_types = ( @statistics_types, @Koha::Statistic::pseudonymization_types ) if defined($statistics_type_pseudo); |
| 247 |
@statistics_types = keys %{ { map { $_, 1 } @statistics_types } }; # remove duplicate types |
253 |
@statistics_types = keys %{ { map { $_, 1 } @statistics_types } }; # remove duplicate types |
|
Lines 419-427
if ($pLogs) {
Link Here
|
| 419 |
$log_query .= " AND action IN (" . join( ',', ('?') x @log_actions ) . ")"; |
425 |
$log_query .= " AND action IN (" . join( ',', ('?') x @log_actions ) . ")"; |
| 420 |
push @query_params, @log_actions; |
426 |
push @query_params, @log_actions; |
| 421 |
} |
427 |
} |
|
|
428 |
if ($logs_batch) { |
| 429 |
$log_query .= " LIMIT ?"; |
| 430 |
push @query_params, $logs_batch; |
| 431 |
} |
| 422 |
$sth = $dbh->prepare($log_query); |
432 |
$sth = $dbh->prepare($log_query); |
| 423 |
if ($confirm) { |
433 |
if ($confirm) { |
| 424 |
$sth->execute( $pLogs, @query_params ) or die $dbh->errstr; |
434 |
if ($logs_batch) { |
|
|
435 |
my $counter = 0; |
| 436 |
my $rows = 0; |
| 437 |
while ( $counter <= $rows ) { |
| 438 |
$sth->execute( $pLogs, @query_params ) or die $dbh->errstr; |
| 439 |
sleep 3; |
| 440 |
$rows += $sth->rows; |
| 441 |
$counter += $logs_batch; |
| 442 |
} |
| 443 |
} else { |
| 444 |
$sth->execute( $pLogs, @query_params ) or die $dbh->errstr; |
| 445 |
} |
| 425 |
} |
446 |
} |
| 426 |
print "Done with purging action_logs.\n" if $verbose; |
447 |
print "Done with purging action_logs.\n" if $verbose; |
| 427 |
} |
448 |
} |
| 428 |
- |
|
|