From 032a0011401fb0e66d5c16bfe88580584acded57 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 28 Jul 2017 16:01:51 +0200 Subject: [PATCH] Bug 19008: More database cleanups - old reserves 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_reserves table. Test plan : - Count : select count(*),date(timestamp) from old_reserves group by date(timestamp); - Run cleanup : misc/cronjobs/cleanup_database.pl -v --old-reserves 30 - Recount Signed-off-by: Mark Tompsett Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson (cherry picked from commit 9ce0f3a73e4de58fb04f4e7977a6299e4b480b5b) Signed-off-by: Lucas Gass --- 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 0bdbbb4757..258a04f904 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, @@ -146,6 +148,7 @@ GetOptions( 'deleted-catalog:i' => \$pDeletedCatalog, 'deleted-patrons:i' => \$pDeletedPatrons, 'old-issues:i' => \$pOldIssues, + 'old-reserves:i' => \$pOldReserves, ) || usage(1); # Use default values @@ -184,6 +187,7 @@ unless ( $sessions || $pDeletedCatalog || $pDeletedPatrons || $pOldIssues + || $pOldReserves ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -448,6 +452,18 @@ if ($pOldIssues) { print "Done with purging old issues.\n" if $verbose; } +if ($pOldReserves) { + print "Purging old reserves older than $pOldReserves days.\n" if $verbose; + $sth = $dbh->prepare( + q{ + DELETE FROM old_reserves + WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + $sth->execute($pOldReserves); + print "Done with purging old reserves.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { -- 2.39.5