View | Details | Raw Unified | Return to bug 13409
Collapse All | Expand All

(-)a/Koha/Calendar.pm (+34 lines)
Lines 88-93 sub exception_holidays { Link Here
88
    return $exception_holidays;
88
    return $exception_holidays;
89
}
89
}
90
90
91
=head cleanupCalendar
92
@STATIC
93
94
    Koha::Calendar::cleanupCalendar( {daysOld => 362} );
95
96
Removes all the special holidays which are more than <daysOld>.
97
@PARAM1 HASHRef,
98
Defaults:
99
    daysOld => 362, #How many days of special holidays we preserve to the past?
100
@RETURNS 1 if operation succeeded
101
@THROWS die-signal if there was an error with the DB-query.
102
103
Pending tests, shame on me!
104
=cut
105
106
sub cleanupCalendar {
107
    my ($params) = @_;
108
109
    my $dbh = C4::Context->dbh; #I know I shouldn't use this, but the Koha::Calendar-module doesn't use DBIx either.
110
111
    my $daysOld = $params->{daysOld} || 362;
112
113
    my $cleanup_sth = $dbh->prepare(
114
        "DELETE FROM special_holidays WHERE TO_DAYS(DATE(CONCAT(year,'-',month,'-',day))) < (TO_DAYS(NOW()) - ?);"
115
    );
116
    $cleanup_sth->execute( $daysOld );
117
    $exception_holidays = undef; #invalidate cache
118
119
    if ($cleanup_sth->errstr) {
120
        die $cleanup_sth->errstr;
121
    }
122
    return 1;
123
}
124
91
sub single_holidays {
125
sub single_holidays {
92
    my ( $self ) = @_;
126
    my ( $self ) = @_;
93
    my $dbh = C4::Context->dbh;
127
    my $dbh = C4::Context->dbh;
(-)a/misc/cronjobs/cleanup_database.pl (-2 / +16 lines)
Lines 59-64 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
59
   --merged           purged completed entries from need_merge_authorities.
59
   --merged           purged completed entries from need_merge_authorities.
60
   --import DAYS      purge records from import tables older than DAYS days.
60
   --import DAYS      purge records from import tables older than DAYS days.
61
                      Defaults to 60 days if no days specified.
61
                      Defaults to 60 days if no days specified.
62
   --calendar DAYS    purge rows from koha.special_holidays-table older than DAYS days.
63
                      Defaults to 362 days if no days specified.
62
   --z3950            purge records from import tables that are the result
64
   --z3950            purge records from import tables that are the result
63
                      of Z39.50 searches
65
                      of Z39.50 searches
64
   --logs DAYS        purge entries from action_logs older than DAYS days.
66
   --logs DAYS        purge entries from action_logs older than DAYS days.
Lines 74-80 USAGE Link Here
74
my (
76
my (
75
    $help,            $sessions,       $sess_days,    $verbose,
77
    $help,            $sessions,       $sess_days,    $verbose,
76
    $zebraqueue_days, $mail,           $purge_merged, $pImport,
78
    $zebraqueue_days, $mail,           $purge_merged, $pImport,
77
    $pLogs,           $pSearchhistory, $pZ3950,
79
    $pLogs,           $pSearchhistory, $pZ3950,       $calendar,
78
    $pListShareInvites,
80
    $pListShareInvites,
79
);
81
);
80
82
Lines 87-92 GetOptions( Link Here
87
    'zebraqueue:i' => \$zebraqueue_days,
89
    'zebraqueue:i' => \$zebraqueue_days,
88
    'merged'       => \$purge_merged,
90
    'merged'       => \$purge_merged,
89
    'import:i'     => \$pImport,
91
    'import:i'     => \$pImport,
92
    'calendar:i'   => \$calendar,
90
    'z3950'        => \$pZ3950,
93
    'z3950'        => \$pZ3950,
91
    'logs:i'       => \$pLogs,
94
    'logs:i'       => \$pLogs,
92
    'searchhistory:i' => \$pSearchhistory,
95
    'searchhistory:i' => \$pSearchhistory,
Lines 112-117 unless ( $sessions Link Here
112
    || $mail
115
    || $mail
113
    || $purge_merged
116
    || $purge_merged
114
    || $pImport
117
    || $pImport
118
    || $calendar
115
    || $pLogs
119
    || $pLogs
116
    || $pSearchhistory
120
    || $pSearchhistory
117
    || $pZ3950
121
    || $pZ3950
Lines 188-193 if($purge_merged) { Link Here
188
    print "Done with purging need_merge_authorities.\n" if $verbose;
192
    print "Done with purging need_merge_authorities.\n" if $verbose;
189
}
193
}
190
194
195
if ($calendar) {
196
    my $daysOld = $calendar || 362;
197
    print "Purging koha.special_holidays from '$calendar' days ago.\n" if $verbose;
198
    eval {
199
        Koha::Calendar::cleanupCalendar();
200
    };
201
    if ($@) {
202
        warn DateTime->now()->iso8601()." - Exception while purging the Calendar:\n".$@;
203
    }
204
}
205
191
if($pImport) {
206
if($pImport) {
192
    print "Purging records from import tables.\n" if $verbose;
207
    print "Purging records from import tables.\n" if $verbose;
193
    PurgeImportTables();
208
    PurgeImportTables();
194
- 

Return to bug 13409