From 69078125d2c76d87b63c7a3bb73a5b833957e389 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 --- 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 975aaabd2a..875a53a986 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); @@ -353,6 +357,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.17.1