From f1ff6c57648ace2b31bca9fb3836d7ac386d2ae6 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Thu, 19 Jan 2023 01:29:37 +0000 Subject: [PATCH] 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 Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Tomas Cohen Arazi --- misc/cronjobs/cleanup_database.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index c33dede4e5..60b3652012 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -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; -- 2.39.5