From 20118bb795ce046c2b00152aeccb94ae998375e6 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 28 Jul 2017 14:12:22 +0200 Subject: [PATCH] Bug 19008: More database cleanups - statistics misc/cronjobs/cleanup_database.pl provides some database cleanup. Yet some tables that could need cleanup are not in this script. This patch adds cleanup for statistics table. Test plan : - Count statistics : select count(*),date(datetime) from statistics group by date(datetime); - Run cleanup : misc/cronjobs/cleanup_database.pl -v --statistics 30 - Recount statistics Signed-off-by: Mark Tompsett Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- misc/cronjobs/cleanup_database.pl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 9d397b5018..db84bf8aa3 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -45,7 +45,7 @@ use Koha::UploadedFiles; sub usage { print STDERR < \$help, @@ -133,6 +135,7 @@ GetOptions( 'temp-uploads-days:i' => \$temp_uploads_days, 'uploads-missing:i' => \$uploads_missing, 'oauth-tokens' => \$oauth_tokens, + 'statistics:i' => \$pStatistics, ) || usage(1); # Use default values @@ -167,6 +170,7 @@ unless ( $sessions || $temp_uploads || defined $uploads_missing || $oauth_tokens + || $pStatistics ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -368,6 +372,18 @@ if ($oauth_tokens) { say "Removed $count expired OAuth2 tokens" if $verbose; } +if ($pStatistics) { + print "Purging statistics older than $pStatistics days.\n" if $verbose; + $sth = $dbh->prepare( + q{ + DELETE FROM statistics + WHERE datetime < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + $sth->execute($pStatistics); + print "Done with purging statistics.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { -- 2.39.5