Bugzilla – Attachment 43588 Details for
Bug 13409
Add ability to purge old special holidays using cleanup_database.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13409 - Add ability to purge old special holidays using cleanup_database.pl v2
Bug-13409---Add-ability-to-purge-old-special-holid.patch (text/plain), 4.34 KB, created by
Olli-Antti Kivilahti
on 2015-10-19 11:47:39 UTC
(
hide
)
Description:
Bug 13409 - Add ability to purge old special holidays using cleanup_database.pl v2
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2015-10-19 11:47:39 UTC
Size:
4.34 KB
patch
obsolete
>From e18258255dc8b6598693353124308d1ba5a4b21d Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Mon, 19 Oct 2015 14:42:15 +0300 >Subject: [PATCH] Bug 13409 - Add ability to purge old special holidays using > cleanup_database.pl v2 > >We are having a massive amount of special holidays in the calendar and those >are cluttering the calendar views. A simple solution is to remove stale >special holidays from the koha.special_holidays-table. > >Test Plan: >1) Create some special holidays in the past >2) Use the new --calendar DAYS option to test deleting special holidays >3) Verify only special holidays past the given amount of days were deleted > >P.S. No test included! Do not push without proper integration tests, > preferably with Cucumber + PageObject and some kind of a cronjob-runner. >--- > Koha/Calendar.pm | 34 ++++++++++++++++++++++++++++++++++ > misc/cronjobs/cleanup_database.pl | 17 ++++++++++++++++- > 2 files changed, 50 insertions(+), 1 deletion(-) > >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >index a4eb3d1..25c83c5 100644 >--- a/Koha/Calendar.pm >+++ b/Koha/Calendar.pm >@@ -88,6 +88,40 @@ sub exception_holidays { > return $exception_holidays; > } > >+=head cleanupCalendar >+@STATIC >+ >+ Koha::Calendar::cleanupCalendar( {daysOld => 362} ); >+ >+Removes all the special holidays which are more than <daysOld>. >+@PARAM1 HASHRef, >+Defaults: >+ daysOld => 362, #How many days of special holidays we preserve to the past? >+@RETURNS 1 if operation succeeded >+@THROWS die-signal if there was an error with the DB-query. >+ >+Pending tests, shame on me! >+=cut >+ >+sub cleanupCalendar { >+ my ($params) = @_; >+ >+ my $dbh = C4::Context->dbh; #I know I shouldn't use this, but the Koha::Calendar-module doesn't use DBIx either. >+ >+ my $daysOld = $params->{daysOld} || 362; >+ >+ my $cleanup_sth = $dbh->prepare( >+ "DELETE FROM special_holidays WHERE TO_DAYS(DATE(CONCAT(year,'-',month,'-',day))) < (TO_DAYS(NOW()) - ?);" >+ ); >+ $cleanup_sth->execute( $daysOld ); >+ $exception_holidays = undef; #invalidate cache >+ >+ if ($cleanup_sth->errstr) { >+ die $cleanup_sth->errstr; >+ } >+ return 1; >+} >+ > sub single_holidays { > my ( $self ) = @_; > my $dbh = C4::Context->dbh; >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index fa27e9b..ec0aa71 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -59,6 +59,8 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu > --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. >+ --calendar DAYS purge rows from koha.special_holidays-table older than DAYS days. >+ Defaults to 362 days if no days specified. > --z3950 purge records from import tables that are the result > of Z39.50 searches > --logs DAYS purge entries from action_logs older than DAYS days. >@@ -74,7 +76,7 @@ USAGE > my ( > $help, $sessions, $sess_days, $verbose, > $zebraqueue_days, $mail, $purge_merged, $pImport, >- $pLogs, $pSearchhistory, $pZ3950, >+ $pLogs, $pSearchhistory, $pZ3950, $calendar, > $pListShareInvites, > ); > >@@ -87,6 +89,7 @@ GetOptions( > 'zebraqueue:i' => \$zebraqueue_days, > 'merged' => \$purge_merged, > 'import:i' => \$pImport, >+ 'calendar:i' => \$calendar, > 'z3950' => \$pZ3950, > 'logs:i' => \$pLogs, > 'searchhistory:i' => \$pSearchhistory, >@@ -112,6 +115,7 @@ unless ( $sessions > || $mail > || $purge_merged > || $pImport >+ || $calendar > || $pLogs > || $pSearchhistory > || $pZ3950 >@@ -188,6 +192,17 @@ if($purge_merged) { > print "Done with purging need_merge_authorities.\n" if $verbose; > } > >+if ($calendar) { >+ my $daysOld = $calendar || 362; >+ print "Purging koha.special_holidays from '$calendar' days ago.\n" if $verbose; >+ eval { >+ Koha::Calendar::cleanupCalendar(); >+ }; >+ if ($@) { >+ warn DateTime->now()->iso8601()." - Exception while purging the Calendar:\n".$@; >+ } >+} >+ > if($pImport) { > print "Purging records from import tables.\n" if $verbose; > PurgeImportTables(); >-- >1.7.9.5
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 13409
:
34177
|
43588
|
43608
|
43609
|
43693
|
43694
|
43695