From f1110c43bac89bbe2fd4b6a628a85d03060e003a 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 --- 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 efe81a1..80bd33b 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, @@ -142,6 +144,7 @@ GetOptions( 'statistics:i' => \$pStatistics, 'deleted-catalog:i' => \$pDeletedCatalog, 'deleted-patrons:i' => \$pDeletedPatrons, + 'old-issues:i' => \$pOldIssues, ) || usage(1); # Use default values @@ -178,6 +181,7 @@ unless ( $sessions || $pStatistics || $pDeletedCatalog || $pDeletedPatrons + || $pOldIssues ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -400,6 +404,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.10.2