Bug 32686: Specify action of action_logs to purge

Add --log-action parameter to cleanup_database.pl

Test plan:
1. Apply patch
2. Enable cataloguing and borrowers log
3. Make some changes to borrowers, create some borrowers, and edit some
biblio records
4. Change the action_logs.timestamp for all action_logs entries to 367
days ago
5. Run cleanup_database.pl with --logs 365 --log-module=MEMBERS
--log-action=CREATE --confirm
6. Confirm only the borrowers creation action_logs entries are removed
7. Run cleanup_database.pl with --logs 365
8. Confirm all action_logs entries are removed

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Alex Buckley 2023-01-19 01:29:37 +00:00 committed by Tomas Cohen Arazi
parent df8aca0252
commit f1ff6c5764
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -84,6 +84,7 @@ Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
or equal to 1.
--log-modules Specify which action log modules to trim. Repeatable.
--preserve-log Specify which action logs to exclude. Repeatable.
--log-action Specify which action log action entries to trim. Repeatable.
--logs DAYS purge entries from action_logs older than DAYS days.
Defaults to 180 days if no days specified.
--searchhistory DAYS purge entries from search_history older than DAYS days.
@ -162,6 +163,7 @@ my $labels;
my $cards;
my @log_modules;
my @preserve_logs;
my @log_actions;
my $jobs_days;
my @jobs_types;
my $reports;
@ -183,6 +185,7 @@ GetOptions(
'logs:i' => \$pLogs,
'log-module:s' => \@log_modules,
'preserve-log:s' => \@preserve_logs,
'log-action:s' => \@log_actions,
'messages:i' => \$pMessages,
'fees:i' => \$fees_days,
'searchhistory:i' => \$pSearchhistory,
@ -386,6 +389,10 @@ if ($pLogs) {
$log_query .= " AND module IN (" . join(',',('?') x @log_modules ) . ")";
push @query_params, @log_modules;
}
if( @log_actions ){
$log_query .= " AND action IN (" . join(',',('?') x @log_actions ) . ")";
push @query_params, @log_actions;
}
$sth = $dbh->prepare( $log_query );
if ( $confirm ) {
$sth->execute($pLogs, @query_params) or die $dbh->errstr;