From 9b5ff17d79a61156426433bdd2e3c248e63d7431 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 28 Jul 2017 14:57:33 +0200 Subject: [PATCH] Bug 19008: More database cleanups - old issues 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 old_issues table. Test plan : - Count : select count(*),date(timestamp) from old_issues group by date(timestamp); - Run cleanup : misc/cronjobs/cleanup_database.pl -v --old-issues 30 - Recount Signed-off-by: Mark Tompsett Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- 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 cfcc1441fb..0e6bd6606b 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, @@ -143,6 +145,7 @@ GetOptions( 'statistics:i' => \$pStatistics, 'deleted-catalog:i' => \$pDeletedCatalog, 'deleted-patrons:i' => \$pDeletedPatrons, + 'old-issues:i' => \$pOldIssues, ) || usage(1); # Use default values @@ -180,6 +183,7 @@ unless ( $sessions || $pStatistics || $pDeletedCatalog || $pDeletedPatrons + || $pOldIssues ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -417,6 +421,18 @@ if ($pDeletedPatrons) { print "Done with purging deleted patrons.\n" if $verbose; } +if ($pOldIssues) { + print "Purging old issues older than $pOldIssues days.\n" if $verbose; + $sth = $dbh->prepare( + q{ + DELETE FROM old_issues + WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + $sth->execute($pOldIssues); + print "Done with purging old issues.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { -- 2.39.5