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

(-)a/misc/cronjobs/cleanup_database.pl (-5 / +26 lines)
Lines 26-31 use constant DEFAULT_LOGS_PURGEDAYS => 180; Link Here
26
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS      => 30;
26
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS      => 30;
27
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14;
27
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14;
28
use constant DEFAULT_DEBARMENTS_PURGEDAYS         => 30;
28
use constant DEFAULT_DEBARMENTS_PURGEDAYS         => 30;
29
use constant DEFAULT_HOLIDAYS_PURGEDAYS           => 30;
29
30
30
BEGIN {
31
BEGIN {
31
    # find Koha's Perl modules
32
    # find Koha's Perl modules
Lines 69-82 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
69
                         days.  Defaults to 14 days if no days specified.
70
                         days.  Defaults to 14 days if no days specified.
70
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
71
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
71
                         Defaults to 30 days if no days specified.
72
                         Defaults to 30 days if no days specified.
73
   --holidays=DAYS       purge special holidays that passed more then DAYS days ago.
74
                         Defaults to 30 days of no days specified.
72
USAGE
75
USAGE
73
    exit $_[0];
76
    exit $_[0];
74
}
77
}
75
78
76
my (
79
my (
77
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
80
    $help,   $sessions,          $sess_days,   $verbose, $zebraqueue_days,
78
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
81
    $mail,   $purge_merged,      $pImport,     $pLogs,   $pSearchhistory,
79
    $pZ3950, $pListShareInvites, $pDebarments,
82
    $pZ3950, $pListShareInvites, $pDebarments, $pHolidays,
80
);
83
);
81
84
82
GetOptions(
85
GetOptions(
Lines 93-98 GetOptions( Link Here
93
    'searchhistory:i' => \$pSearchhistory,
96
    'searchhistory:i' => \$pSearchhistory,
94
    'list-invites:i'  => \$pListShareInvites,
97
    'list-invites:i'  => \$pListShareInvites,
95
    'restrictions:i'  => \$pDebarments,
98
    'restrictions:i'  => \$pDebarments,
99
    'holidays:i'      => \$pHolidays
96
) || usage(1);
100
) || usage(1);
97
101
98
# Use default values
102
# Use default values
Lines 104-109 $mail = DEFAULT_MAIL_PURGEDAYS if defined($mail) Link Here
104
$pSearchhistory    = DEFAULT_SEARCHHISTORY_PURGEDAYS      if defined($pSearchhistory)    && $pSearchhistory == 0;
108
$pSearchhistory    = DEFAULT_SEARCHHISTORY_PURGEDAYS      if defined($pSearchhistory)    && $pSearchhistory == 0;
105
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0;
109
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0;
106
$pDebarments       = DEFAULT_DEBARMENTS_PURGEDAYS         if defined($pDebarments)       && $pDebarments == 0;
110
$pDebarments       = DEFAULT_DEBARMENTS_PURGEDAYS         if defined($pDebarments)       && $pDebarments == 0;
111
$pHolidays         = DEFAULT_HOLIDAYS_PURGEDAYS           if defined($pHolidays)         && $pHolidays == 0;
107
112
108
if ($help) {
113
if ($help) {
109
    usage(0);
114
    usage(0);
Lines 118-124 unless ( $sessions Link Here
118
    || $pSearchhistory
123
    || $pSearchhistory
119
    || $pZ3950
124
    || $pZ3950
120
    || $pListShareInvites
125
    || $pListShareInvites
121
    || $pDebarments )
126
    || $pDebarments
127
    || $pHolidays )
122
{
128
{
123
    print "You did not specify any cleanup work for the script to do.\n\n";
129
    print "You did not specify any cleanup work for the script to do.\n\n";
124
    usage(1);
130
    usage(1);
Lines 238-243 if ($pDebarments) { Link Here
238
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
244
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
239
}
245
}
240
246
247
if ($pHolidays) {
248
    print "Passed special holidays purge triggered for $pHolidays days.\n" if $verbose;
249
    PurgeHolidays();
250
    print "Done with holidays purge.\n" if $verbose;
251
}
252
241
exit(0);
253
exit(0);
242
254
243
sub RemoveOldSessions {
255
sub RemoveOldSessions {
Lines 324-326 sub PurgeDebarments { Link Here
324
    }
336
    }
325
    return $count;
337
    return $count;
326
}
338
}
327
- 
339
340
sub PurgeHolidays {
341
    $sth = $dbh->prepare(
342
        q{
343
            DELETE FROM special_holidays
344
            WHERE DATE( CONCAT( year, '-', month, '-', day ) ) < DATE_SUB( CURDATE(), INTERVAL ? DAY )
345
        }
346
    );
347
    $sth->execute( $pHolidays ) or die $dbh->errstr;
348
}

Return to bug 13409