From 91d67cffcf0193ef61f0637062780e3725605270 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 --- 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 03c382d..f1e093b 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -44,7 +44,7 @@ use Koha::UploadedFiles; sub usage { print STDERR < \$help, @@ -132,6 +134,7 @@ GetOptions( 'temp-uploads' => \$temp_uploads, 'temp-uploads-days:i' => \$temp_uploads_days, 'uploads-missing:i' => \$uploads_missing, + 'statistics:i' => \$pStatistics, ) || usage(1); # Use default values @@ -165,6 +168,7 @@ unless ( $sessions || $special_holidays_days || $temp_uploads || defined $uploads_missing + || $pStatistics ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -336,6 +340,18 @@ if( defined $uploads_missing ) { } } +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.7.4