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 {