From 35e55854d4c5e51b5bebcd0da4a4134178e7f43a Mon Sep 17 00:00:00 2001 From: Barton Chittenden Date: Thu, 16 Jul 2015 12:25:08 -0700 Subject: [PATCH] Add --fees option to cleanup_database.pl http://bugs.koha-community.org/show_bug.cgi?id=14402 --- misc/cronjobs/cleanup_database.pl | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index cd92dc4..8797915 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -42,7 +42,7 @@ use C4::Log; sub usage { print STDERR < \$pImport, 'z3950' => \$pZ3950, 'logs:i' => \$pLogs, + 'fees:i' => \$fees_days, 'searchhistory:i' => \$pSearchhistory, 'list-invites:i' => \$pListShareInvites, 'restrictions:i' => \$pDebarments, @@ -116,6 +120,7 @@ unless ( $sessions || $purge_merged || $pImport || $pLogs + || $fees_days || $pSearchhistory || $pZ3950 || $pListShareInvites @@ -222,6 +227,12 @@ if ($pLogs) { print "Done with purging action_logs.\n" if $verbose; } +if ($fees_days) { + print "Purging records from accountlines.\n" if $verbose; + PurgeFees( $fees_days ); + print "Done purging records from accountlines.\n" if $verbose; +} + if ($pSearchhistory) { print "Purging records older than $pSearchhistory from search_history.\n" if $verbose; PurgeSearchHistory($pSearchhistory); @@ -340,3 +351,17 @@ sub PurgeDebarments { } return $count; } + +sub PurgeFees { + my $days = shift; + my $count = 0; + + $sth = $dbh->prepare( + q{ + DELETE FROM accountlines + WHERE date < date_sub(curdate(), INTERVAL ? DAY) + AND amountoutstanding = 0; + } + ); + $sth->execute($days) or die $dbh->errstr; +} -- 1.7.10.4