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

(-)a/misc/cronjobs/cleanup_database.pl (-2 / +26 lines)
Lines 42-48 use C4::Log; Link Here
42
42
43
sub usage {
43
sub usage {
44
    print STDERR <<USAGE;
44
    print STDERR <<USAGE;
45
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions]
45
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS]
46
46
47
   -h --help          prints this help message, and exits, ignoring all
47
   -h --help          prints this help message, and exits, ignoring all
48
                      other options
48
                      other options
Lines 60-65 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
60
                      Defaults to 60 days if no days specified.
60
                      Defaults to 60 days if no days specified.
61
   --z3950            purge records from import tables that are the result
61
   --z3950            purge records from import tables that are the result
62
                      of Z39.50 searches
62
                      of Z39.50 searches
63
   --fees DAYS        purge entries accountlines older than DAYS days, where
64
                      amountoutstanding is 0.
63
   --logs DAYS        purge entries from action_logs older than DAYS days.
65
   --logs DAYS        purge entries from action_logs older than DAYS days.
64
                      Defaults to 180 days if no days specified.
66
                      Defaults to 180 days if no days specified.
65
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
67
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
Lines 77-82 my ( Link Here
77
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
79
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
78
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
80
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
79
    $pZ3950, $pListShareInvites, $pDebarments, $allDebarments,
81
    $pZ3950, $pListShareInvites, $pDebarments, $allDebarments,
82
    $fees_days
80
);
83
);
81
84
82
GetOptions(
85
GetOptions(
Lines 90-95 GetOptions( Link Here
90
    'import:i'        => \$pImport,
93
    'import:i'        => \$pImport,
91
    'z3950'           => \$pZ3950,
94
    'z3950'           => \$pZ3950,
92
    'logs:i'          => \$pLogs,
95
    'logs:i'          => \$pLogs,
96
    'fees:i'          => \$fees_days,
93
    'searchhistory:i' => \$pSearchhistory,
97
    'searchhistory:i' => \$pSearchhistory,
94
    'list-invites:i'  => \$pListShareInvites,
98
    'list-invites:i'  => \$pListShareInvites,
95
    'restrictions:i'  => \$pDebarments,
99
    'restrictions:i'  => \$pDebarments,
Lines 116-121 unless ( $sessions Link Here
116
    || $purge_merged
120
    || $purge_merged
117
    || $pImport
121
    || $pImport
118
    || $pLogs
122
    || $pLogs
123
    || $fees_days
119
    || $pSearchhistory
124
    || $pSearchhistory
120
    || $pZ3950
125
    || $pZ3950
121
    || $pListShareInvites
126
    || $pListShareInvites
Lines 222-227 if ($pLogs) { Link Here
222
    print "Done with purging action_logs.\n" if $verbose;
227
    print "Done with purging action_logs.\n" if $verbose;
223
}
228
}
224
229
230
if ($fees_days) {
231
    print "Purging records from accountlines.\n" if $verbose;
232
    PurgeFees( $fees_days );
233
    print "Done purging records from accountlines.\n" if $verbose;
234
}
235
225
if ($pSearchhistory) {
236
if ($pSearchhistory) {
226
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
237
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
227
    PurgeSearchHistory($pSearchhistory);
238
    PurgeSearchHistory($pSearchhistory);
Lines 340-342 sub PurgeDebarments { Link Here
340
    }
351
    }
341
    return $count;
352
    return $count;
342
}
353
}
343
- 
354
355
sub PurgeFees {
356
    my $days  = shift;
357
    my $count = 0;
358
359
    $sth   = $dbh->prepare(
360
        q{
361
            DELETE FROM accountlines
362
            WHERE date < date_sub(curdate(), INTERVAL ? DAY)
363
              AND amountoutstanding = 0;
364
        }
365
    );
366
    $sth->execute($days) or die $dbh->errstr;
367
}

Return to bug 14402