Bugzilla – Attachment 123857 Details for
Bug 18631
`cleanup_database.pl` should take an option for modules in action_logs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18631: Add option to specify logs to preserve or delete in cleanup_database.pl
Bug-18631-Add-option-to-specify-logs-to-preserve-o.patch (text/plain), 4.33 KB, created by
Andrew Fuerste-Henry
on 2021-08-16 19:00:50 UTC
(
hide
)
Description:
Bug 18631: Add option to specify logs to preserve or delete in cleanup_database.pl
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2021-08-16 19:00:50 UTC
Size:
4.33 KB
patch
obsolete
>From 5685d79cc242d3be74ecfcd3be744880f36f2232 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 21 Jul 2021 19:15:27 +0000 >Subject: [PATCH] Bug 18631: Add option to specify logs to preserve or delete > in cleanup_database.pl > >This adds two new parameters: >--log_module >--preserve_log > >These can be repeated to include or exclude specific modules from the cleanup > >To test: >0 - Apply patch >1 - Enable cataloging log and borrowers log >2 - Make some changes to borrowers and records >3 - run cleanup databse with --logs 0 --preserve_log=MEMBERS --preserve_log=CATALOGUING >4 - nothing is removed >5 - run cleanup databse with --logs 0 --log_module=MEMBERS >6 - the borrower logs are removed, the record changes remain >7 - run cleanup database with --logs 0 >8 - record changes are removed (all other logs too) > >Signed-off-by: > >Signed-off-by: > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> > >Signed-off-by: Rebecca Coert <rcoert@arlingtonva.us> >--- > Koha/XSLT/Base.pm | 3 +++ > misc/cronjobs/cleanup_database.pl | 24 +++++++++++++++++++----- > 2 files changed, 22 insertions(+), 5 deletions(-) > >diff --git a/Koha/XSLT/Base.pm b/Koha/XSLT/Base.pm >index 7b6134994f..36ae40c8be 100644 >--- a/Koha/XSLT/Base.pm >+++ b/Koha/XSLT/Base.pm >@@ -215,6 +215,7 @@ sub transform { > $self->_set_error( XSLTH_ERR_5, $@ ); > return $retval; > } >+ warn $format; > my $result = eval { > #$parameters is an optional hashref that contains > #key-value pairs to be sent to the XSLT. >@@ -224,6 +225,7 @@ sub transform { > > #NOTE: Parameters are not cached. They are provided for > #each different transform. >+ warn Data::Dumper::Dumper( $stsh ); > my $transformed = $stsh->transform($source, %$parameters); > $format eq 'bytes' > ? $stsh->output_as_bytes( $transformed ) >@@ -314,6 +316,7 @@ sub _load { > return $digest.$codelen; > } > } elsif( $filename && exists $self->{xslt_hash}->{$filename} ) { >+ warn "Already"; > return $filename; > } > >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 94a6301620..eefbf8b82e 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -80,6 +80,8 @@ 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. >+ --log_modules Specify which action log modules to trim. Repeatable. >+ --preserve_logs Specify which action logs to exclude. Repeatable. > --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. >@@ -148,6 +150,8 @@ my $pMessages; > my $lock_days = C4::Context->preference('LockExpiredDelay'); > my $labels; > my $cards; >+my @log_modules; >+my @preserve_logs; > > GetOptions( > 'h|help' => \$help, >@@ -161,6 +165,8 @@ GetOptions( > 'import:i' => \$pImport, > 'z3950' => \$pZ3950, > 'logs:i' => \$pLogs, >+ 'log_module:s' => \@log_modules, >+ 'preserve_log:s' => \@preserve_logs, > 'messages:i' => \$pMessages, > 'fees:i' => \$fees_days, > 'searchhistory:i' => \$pSearchhistory, >@@ -341,14 +347,22 @@ if ($pZ3950) { > > if ($pLogs) { > print "Purging records from action_logs.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >+ my $log_query = q{ > DELETE FROM action_logs > WHERE timestamp < date_sub(curdate(), INTERVAL ? DAY) >- } >- ); >+ }; >+ my @query_params = (); >+ if( @preserve_logs ){ >+ $log_query .= " AND module NOT IN (" . join(',',('?') x @preserve_logs ) . ")"; >+ push @query_params, @preserve_logs; >+ } >+ if( @log_modules ){ >+ $log_query .= " AND module IN (" . join(',',('?') x @log_modules ) . ")"; >+ push @query_params, @log_modules; >+ } >+ $sth = $dbh->prepare( $log_query ); > if ( $confirm ) { >- $sth->execute($pLogs) or die $dbh->errstr; >+ $sth->execute($pLogs, @query_params) or die $dbh->errstr; > } > print "Done with purging action_logs.\n" if $verbose; > } >-- >2.20.1
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 18631
:
123231
|
123857
|
125485
|
125864