From 4c0e9d29cf858662f6227dbdc8fd129de41f271f Mon Sep 17 00:00:00 2001 From: Timothy Alexis Vass Date: Fri, 4 Dec 2020 14:34:16 +0000 Subject: [PATCH] Bug 27080: Add --statute-barred-fees option to cleanup_database.pl. According to Swedish law, fees become statute-barred after 3 years if the material has been returned. With this option, we can use cleanup_database.pl to purge those from accountlines. To test: 1) You will need at least one record in the accountlines table WHERE status = 'RETURNED' AND amountoutstanding > 0. 2) Run ./misc/cronjobs/cleanup_database.pl --statute-barred-fees DAYS Where DAYS is 1 or greater. This will delete records from accountlines WHERE date is DAYS day(s) or older. 3) Confirm that records have been deleted. Sponsored-by: Lunds Universitetsbibliotek --- misc/cronjobs/cleanup_database.pl | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index c2d8e9832c..ded97581be 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -41,6 +41,9 @@ use C4::Search::History; use Getopt::Long; use C4::Log; use C4::Accounts; +use Koha::Database; +use Koha::DateUtils; +use Koha::Account::Lines; use Koha::UploadedFiles; use Koha::Old::Biblios; use Koha::Old::Items; @@ -53,7 +56,7 @@ use Koha::PseudonymizedTransactions; sub usage { print STDERR < \$pZ3950, 'logs:i' => \$pLogs, 'fees:i' => \$fees_days, + 'statute-barred-fees:i' => \$statue_barred_fees_days, 'searchhistory:i' => \$pSearchhistory, 'list-invites:i' => \$pListShareInvites, 'restrictions:i' => \$pDebarments, @@ -194,6 +203,7 @@ unless ( $sessions || $pImport || $pLogs || $fees_days + || $statue_barred_fees_days || $pSearchhistory || $pZ3950 || $pListShareInvites @@ -231,6 +241,7 @@ cronlogaction() unless $confirm; my $dbh = C4::Context->dbh(); my $sth; my $sth2; +my $dtf = Koha::Database->new->schema->storage->datetime_parser; if ( $sessions && !$sess_days ) { if ($verbose) { @@ -340,6 +351,23 @@ if ($fees_days) { print "Done purging records from accountlines.\n" if $verbose; } +if ($statue_barred_fees_days) { + my $date = $dtf->format_datetime( DateTime->now->subtract(days => $statue_barred_fees_days) ); + my $accountlines = Koha::Account::Lines->search({ + amountoutstanding => { '>' => 0 }, + status => 'RETURNED', + date => { '<=' => $date } + }); + if ( $confirm ) { + say "Purging " . $accountlines->count . " statute-barred fees from accountlines." if $verbose; + $accountlines->delete; + } + else { + say $accountlines->count . " statute-barred fees would have been deleted." if $verbose; + } + say "Done purging statute-barred fees from accountlines." if $verbose; +} + if ($pSearchhistory) { print "Purging records older than $pSearchhistory from search_history.\n" if $verbose; C4::Search::History::delete({ interval => $pSearchhistory }) if $confirm; -- 2.11.0