Bugzilla – Attachment 113939 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 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-option-to-cleanup.patch (text/plain), 15.82 KB, created by
Timothy Alexis Vass
on 2020-11-24 08:15:17 UTC
(
hide
)
Description:
Bug 27080 - Add --statute-barred 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-11-24 08:15:17 UTC
Size:
15.82 KB
patch
obsolete
>From 81006eaeb534416e324885cdb2dbffcf4a50db13 Mon Sep 17 00:00:00 2001 >From: Timothy Alexis Vass <timothy_alexis.vass@ub.lu.se> >Date: Tue, 24 Nov 2020 08:07:31 +0000 >Subject: [PATCH] Bug 27080 - Add --statute-barred 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 a record in the accountlines table WHERE status = 'REMOVED' AND amountoutstanding > 0. >2) Run ./misc/cronjobs/cleanup_database.pl --statute-barred 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 >--- > C4/Accounts.pm | 31 +++++++ > misc/cronjobs/cleanup_database.pl | 179 +++++++++++++++++++++----------------- > 2 files changed, 129 insertions(+), 81 deletions(-) > >diff --git a/C4/Accounts.pm b/C4/Accounts.pm >index 7d7ac76018..a89a412b77 100644 >--- a/C4/Accounts.pm >+++ b/C4/Accounts.pm >@@ -39,6 +39,7 @@ BEGIN { > @EXPORT = qw( > &chargelostitem > &purge_zero_balance_fees >+ &purge_statute_barred_fees > ); > } > >@@ -171,6 +172,36 @@ sub purge_zero_balance_fees { > $sth->execute($days) or die $dbh->errstr; > } > >+=head2 purge_statute_barred_fees >+ >+ purge_statute_barred_fees( $days ); >+ >+Delete accountlines entries where status is RETURNED and amountoutstanding is greater than 0 which are more than a given number of days old. >+ >+B<$days> -- Statute-barred fees older than B<$days> days old will be deleted. >+ >+B<Warning:> Because fines and payments are not linked in accountlines, it is >+possible for a fine to be deleted without the accompanying payment, >+or vise versa. This won't affect the account balance, but might be >+confusing to staff. >+ >+=cut >+ >+sub purge_statute_barred_fees { >+ my $days = shift; >+ >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare( >+ q{ >+ DELETE FROM accountlines >+ WHERE date < date_sub(curdate(), INTERVAL ? DAY) >+ AND status = 'RETURNED' >+ AND amountoutstanding > 0 >+ } >+ ); >+ $sth->execute($days) or die $dbh->errstr; >+} >+ > END { } # module clean-up code here (global destructor) > > 1; >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index c2d8e9832c..ca7bb537cc 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -53,56 +53,64 @@ 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] >- >- -h --help prints this help message, and exits, ignoring all >- other options >- --confirm Confirmation flag, the script will be running in dry-run mode is not set. >- --sessions purge the sessions table. If you use this while users >- are logged into Koha, they will have to reconnect. >- --sessdays DAYS purge only sessions older than DAYS days. >- -v --verbose will cause the script to give you a bit more information >- about the run. >- --zebraqueue DAYS purge completed zebraqueue entries older than DAYS days. >- Defaults to 30 days if no days specified. >- -m --mail DAYS purge items from the mail queue that are older than DAYS days. >- Defaults to 30 days if no days specified. >- --merged purged completed entries from need_merge_authorities. >- --import DAYS purge records from import tables older than DAYS days. >- Defaults to 60 days if no days specified. >- --z3950 purge records from import tables that are the result >- of Z39.50 searches >- --fees DAYS purge entries accountlines older than DAYS days, where >- amountoutstanding is 0 or NULL. >- In the case of --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. >- Defaults to 30 days if no days specified >- --list-invites DAYS purge (unaccepted) list share invites older than DAYS >- days. Defaults to 14 days if no days specified. >- --restrictions DAYS purge patrons restrictions expired since more than DAYS days. >- Defaults to 30 days if no days specified. >- --all-restrictions purge all expired patrons restrictions. >- --del-exp-selfreg Delete expired self registration accounts >- --del-unv-selfreg DAYS Delete unverified self registrations older than DAYS >- --unique-holidays DAYS Delete all unique holidays older than DAYS >- --temp-uploads Delete temporary uploads. >- --temp-uploads-days DAYS Override the corresponding preference value. >- --uploads-missing FLAG Delete upload records for missing files when FLAG is true, count them otherwise >- --oauth-tokens Delete expired OAuth2 tokens >- --statistics DAYS Purge statistics entries more than DAYS days old. >- This table is used to build reports, make sure you are aware of the consequences of this before using it! >- --deleted-catalog DAYS Purge catalog records deleted more then DAYS days ago >- (from tables deleteditems, deletedbiblioitems, deletedbiblio_metadata and deletedbiblio). >- --deleted-patrons DAYS Purge patrons deleted more than DAYS days ago. >- --old-issues DAYS Purge checkouts (old_issues) returned more than DAYS days ago. >- --old-reserves DAYS Purge reserves (old_reserves) more than DAYS old. >- --transfers DAYS Purge transfers completed more than DAYS day ago. >- --pseudo-transactions DAYS Purge the pseudonymized transactions that have been originally created more than DAYS days ago >+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 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 >+ --confirm Confirmation flag, the script will be running in dry-run mode is not set. >+ --sessions Purge the sessions table. If you use this while users >+ are logged into Koha, they will have to reconnect. >+ --sessdays DAYS Purge only sessions older than DAYS days. >+ -v --verbose Will cause the script to give you a bit more information >+ about the run. >+ --zebraqueue DAYS Purge completed zebraqueue entries older than DAYS days. >+ Defaults to 30 days if no days specified. >+ -m --mail DAYS Purge items from the mail queue that are older than DAYS days. >+ Defaults to 30 days if no days specified. >+ --merged Purge completed entries from need_merge_authorities. >+ --import DAYS Purge records from import tables older than DAYS days. >+ Defaults to 60 days if no days specified. >+ --z3950 Purge records from import tables that are the result >+ of Z39.50 searches >+ --fees DAYS Purge entries accountlines older than DAYS days, where >+ amountoutstanding is 0 or NULL. >+ In the case of --fees, DAYS must be greater than >+ or equal to 1. >+ --statute-barred DAYS Purge entries accountlines older than DAYS days, where >+ status is RETURNED and amountoutstanding is greater than 0. >+ In the case of --statute-barred, 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. >+ Defaults to 30 days if no days specified >+ --list-invites DAYS Purge (unaccepted) list share invites older than DAYS >+ days. Defaults to 14 days if no days specified. >+ --restrictions DAYS Purge patrons restrictions expired since more than DAYS days. >+ Defaults to 30 days if no days specified. >+ --all-restrictions Purge all expired patrons restrictions. >+ --del-exp-selfreg Delete expired self registration accounts >+ --del-unv-selfreg DAYS Delete unverified self registrations older than DAYS >+ --unique-holidays DAYS Delete all unique holidays older than DAYS >+ --temp-uploads Delete temporary uploads. >+ --temp-uploads-days DAYS Override the corresponding preference value. >+ --uploads-missing FLAG Delete upload records for missing files when FLAG is true, >+ count them otherwise >+ --oauth-tokens Delete expired OAuth2 tokens >+ --statistics DAYS Purge statistics entries more than DAYS days old. >+ This table is used to build reports, make sure you are >+ aware of the consequences of this before using it! >+ --deleted-catalog DAYS Purge catalog records deleted more then DAYS days ago >+ (from tables deleteditems, deletedbiblioitems, >+ deletedbiblio_metadata and deletedbiblio). >+ --deleted-patrons DAYS Purge patrons deleted more than DAYS days ago. >+ --old-issues DAYS Purge checkouts (old_issues) returned more than DAYS days ago. >+ --old-reserves DAYS Purge reserves (old_reserves) more than DAYS old. >+ --transfers DAYS Purge transfers completed more than DAYS day ago. >+ --pseudo-transactions DAYS Purge the pseudonymized transactions that have been >+ originally created more than DAYS days ago > DAYS is optional and can be replaced by: >- --pseudo-transactions-from YYYY-MM-DD and/or --pseudo-transactions-to YYYY-MM-DD >+ --pseudo-transactions-from YYYY-MM-DD >+ and/or --pseudo-transactions-to YYYY-MM-DD > USAGE > exit $_[0]; > } >@@ -125,6 +133,7 @@ my $allDebarments; > my $pExpSelfReg; > my $pUnvSelfReg; > my $fees_days; >+my $statute_barred_days; > my $special_holidays_days; > my $temp_uploads; > my $temp_uploads_days; >@@ -139,38 +148,39 @@ my $pTransfers; > my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo ); > > GetOptions( >- 'h|help' => \$help, >- 'confirm' => \$confirm, >- 'sessions' => \$sessions, >- 'sessdays:i' => \$sess_days, >- 'v|verbose' => \$verbose, >- 'm|mail:i' => \$mail, >- 'zebraqueue:i' => \$zebraqueue_days, >- 'merged' => \$purge_merged, >- 'import:i' => \$pImport, >- 'z3950' => \$pZ3950, >- 'logs:i' => \$pLogs, >- 'fees:i' => \$fees_days, >- 'searchhistory:i' => \$pSearchhistory, >- 'list-invites:i' => \$pListShareInvites, >- 'restrictions:i' => \$pDebarments, >- 'all-restrictions' => \$allDebarments, >- 'del-exp-selfreg' => \$pExpSelfReg, >- 'del-unv-selfreg' => \$pUnvSelfReg, >- 'unique-holidays:i' => \$special_holidays_days, >- 'temp-uploads' => \$temp_uploads, >- 'temp-uploads-days:i' => \$temp_uploads_days, >- 'uploads-missing:i' => \$uploads_missing, >- 'oauth-tokens' => \$oauth_tokens, >- 'statistics:i' => \$pStatistics, >- 'deleted-catalog:i' => \$pDeletedCatalog, >- 'deleted-patrons:i' => \$pDeletedPatrons, >- 'old-issues:i' => \$pOldIssues, >- 'old-reserves:i' => \$pOldReserves, >- 'transfers:i' => \$pTransfers, >- 'pseudo-transactions:i' => \$pPseudoTransactions, >- 'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom, >- 'pseudo-transactions-to:s' => \$pPseudoTransactionsTo, >+ 'h|help' => \$help, >+ 'confirm' => \$confirm, >+ 'sessions' => \$sessions, >+ 'sessdays:i' => \$sess_days, >+ 'v|verbose' => \$verbose, >+ 'm|mail:i' => \$mail, >+ 'zebraqueue:i' => \$zebraqueue_days, >+ 'merged' => \$purge_merged, >+ 'import:i' => \$pImport, >+ 'z3950' => \$pZ3950, >+ 'logs:i' => \$pLogs, >+ 'fees:i' => \$fees_days, >+ 'statute-barred:i' => \$statute_barred_days, >+ 'searchhistory:i' => \$pSearchhistory, >+ 'list-invites:i' => \$pListShareInvites, >+ 'restrictions:i' => \$pDebarments, >+ 'all-restrictions' => \$allDebarments, >+ 'del-exp-selfreg' => \$pExpSelfReg, >+ 'del-unv-selfreg' => \$pUnvSelfReg, >+ 'unique-holidays:i' => \$special_holidays_days, >+ 'temp-uploads' => \$temp_uploads, >+ 'temp-uploads-days:i' => \$temp_uploads_days, >+ 'uploads-missing:i' => \$uploads_missing, >+ 'oauth-tokens' => \$oauth_tokens, >+ 'statistics:i' => \$pStatistics, >+ 'deleted-catalog:i' => \$pDeletedCatalog, >+ 'deleted-patrons:i' => \$pDeletedPatrons, >+ 'old-issues:i' => \$pOldIssues, >+ 'old-reserves:i' => \$pOldReserves, >+ 'transfers:i' => \$pTransfers, >+ 'pseudo-transactions:i' => \$pPseudoTransactions, >+ 'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom, >+ 'pseudo-transactions-to:s' => \$pPseudoTransactionsTo, > ) || usage(1); > > # Use default values >@@ -194,6 +204,7 @@ unless ( $sessions > || $pImport > || $pLogs > || $fees_days >+ || $statute_barred_days > || $pSearchhistory > || $pZ3950 > || $pListShareInvites >@@ -340,6 +351,12 @@ if ($fees_days) { > print "Done purging records from accountlines.\n" if $verbose; > } > >+if ($statute_barred_days) { >+ print "Purging statute-barred fees from accountlines.\n" if $verbose; >+ purge_statute_barred_fees( $statute_barred_days ); >+ print "Done purging statute-barred fees from accountlines.\n" 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