From 212d3c943467bb700c4b83a26167c8b9578366dd Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 28 Jul 2017 14:05:03 +0200 Subject: [PATCH] Bug 19008 - More database cleanups - deleted catalog 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 deleted catalog tables. Note that deletedbiblio_metadata is managed by foreign key on biblionumber. Test plan : - Count : select count(*),year(timestamp) from deleteditems group by year(timestamp); select count(*),year(timestamp) from deletedbiblio group by year(timestamp); select count(*),year(timestamp) from deletedbiblioitems group by year(timestamp); - Run cleanup : misc/cronjobs/cleanup_database.pl -v --deleted-catalog 30 - Recount Signed-off-by: Mark Tompsett --- misc/cronjobs/cleanup_database.pl | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index f1e093b..f503bdc 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, @@ -135,6 +138,7 @@ GetOptions( 'temp-uploads-days:i' => \$temp_uploads_days, 'uploads-missing:i' => \$uploads_missing, 'statistics:i' => \$pStatistics, + 'deleted-catalog:i' => \$pDeletedCatalog, ) || usage(1); # Use default values @@ -169,6 +173,7 @@ unless ( $sessions || $temp_uploads || defined $uploads_missing || $pStatistics + || $pDeletedCatalog ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -352,6 +357,33 @@ if ($pStatistics) { print "Done with purging statistics.\n" if $verbose; } +if ($pDeletedCatalog) { + print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose; + my $sth1 = $dbh->prepare( + q{ + DELETE FROM deleteditems + WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + my $sth2 = $dbh->prepare( + q{ + DELETE FROM deletedbiblioitems + WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + my $sth3 = $dbh->prepare( + q{ + DELETE FROM deletedbiblio + WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + # deletedbiblio_metadata is managed by FK with deletedbiblio + $sth1->execute($pDeletedCatalog); + $sth2->execute($pDeletedCatalog); + $sth3->execute($pDeletedCatalog); + print "Done with purging deleted catalog.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { -- 2.1.4