Bugzilla – Attachment 114202 Details for
Bug 27080
Add --statute-barred-fees option to cleanup_database.pl to purge all fees where the item has been returned and the fee is older than the given number of days.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27080: Add --statute-barred-fees option to cleanup_database.pl to purge all fees where the item has been returned and the fee is older than the given number of days.
Bug-27080-Add---statute-barred-fees-option-to-clea.patch (text/plain), 5.32 KB, created by
Timothy Alexis Vass
on 2020-12-04 14:55:27 UTC
(
hide
)
Description:
Bug 27080: Add --statute-barred-fees option to cleanup_database.pl to purge all fees where the item has been returned and the fee is older than the given number of days.
Filename:
MIME Type:
Creator:
Timothy Alexis Vass
Created:
2020-12-04 14:55:27 UTC
Size:
5.32 KB
patch
obsolete
>From 08c62a4a43ff2ad1ddd96769eb9875f814799045 Mon Sep 17 00:00:00 2001 >From: Timothy Alexis Vass <timothy_alexis.vass@ub.lu.se> >Date: Fri, 4 Dec 2020 14:34:16 +0000 >Subject: [PATCH] Bug 27080: Add --statute-barred-fees option to > cleanup_database.pl to purge all fees where the item has been returned and > the fee is older than the given number of days. > >According to Swedish law, fees become statute-barred after 3 years. >With this option, we can use cleanup_database.pl to purge those from accountlines. > >NOTE: This commit also fixes indentations. >You can use the -w option with git to ignore space differences. > >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..e0085693d6 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 <<USAGE; >-Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] >+Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--statute-barred-fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] > > -h --help prints this help message, and exits, ignoring all > other options >@@ -76,6 +79,10 @@ Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] > amountoutstanding is 0 or NULL. > In the case of --fees, DAYS must be greater than > or equal to 1. >+ --statute-barred-fees DAYS Purge entries accountlines older than DAYS days, where >+ status is RETURNED and amountoutstanding is greater than 0. >+ In the case of --statute-barred-fees, DAYS must be greater than >+ or equal to 1. > --logs DAYS purge entries from action_logs older than DAYS days. > Defaults to 180 days if no days specified. > --searchhistory DAYS purge entries from search_history older than DAYS days. >@@ -125,6 +132,7 @@ my $allDebarments; > my $pExpSelfReg; > my $pUnvSelfReg; > my $fees_days; >+my $statue_barred_fees_days; > my $special_holidays_days; > my $temp_uploads; > my $temp_uploads_days; >@@ -151,6 +159,7 @@ GetOptions( > 'z3950' => \$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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27080
:
113939
|
114083
|
114202
|
114322
|
114323
|
114340