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

(-)a/misc/cronjobs/cleanup_database.pl (-30 / +41 lines)
Lines 23-28 use warnings; Link Here
23
use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30;
23
use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30;
24
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
24
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
25
use constant DEFAULT_LOGS_PURGEDAYS => 180;
25
use constant DEFAULT_LOGS_PURGEDAYS => 180;
26
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30;
26
27
27
BEGIN {
28
BEGIN {
28
    # find Koha's Perl modules
29
    # find Koha's Perl modules
Lines 38-90 use Getopt::Long; Link Here
38
39
39
sub usage {
40
sub usage {
40
    print STDERR <<USAGE;
41
    print STDERR <<USAGE;
41
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS]
42
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS]
42
43
43
   -h --help          prints this help message, and exits, ignoring all
44
   -h --help             prints this help message, and exits, ignoring all
44
                      other options
45
                         other options
45
   --sessions         purge the sessions table.  If you use this while users 
46
   --sessions            purge the sessions table.  If you use this while users 
46
                      are logged into Koha, they will have to reconnect.
47
                         are logged into Koha, they will have to reconnect.
47
   --sessdays DAYS    purge only sessions older than DAYS days.
48
   --sessdays DAYS       purge only sessions older than DAYS days.
48
   -v --verbose       will cause the script to give you a bit more information
49
   -v --verbose          will cause the script to give you a bit more information
49
                      about the run.
50
                         about the run.
50
   --zebraqueue DAYS  purge completed zebraqueue entries older than DAYS days.
51
   --zebraqueue DAYS     purge completed zebraqueue entries older than DAYS days.
51
                      Defaults to 30 days if no days specified.
52
                         Defaults to 30 days if no days specified.
52
   -m --mail          purge the mail queue. 
53
   -m --mail             purge the mail queue. 
53
   --merged           purged completed entries from need_merge_authorities.
54
   --merged              purged completed entries from need_merge_authorities.
54
   --import DAYS      purge records from import tables older than DAYS days.
55
   --import DAYS         purge records from import tables older than DAYS days.
55
                      Defaults to 60 days if no days specified.
56
                         Defaults to 60 days if no days specified.
56
   --logs DAYS        purge entries from action_logs older than DAYS days.
57
   --logs DAYS           purge entries from action_logs older than DAYS days.
57
                      Defaults to 180 days if no days specified.
58
                         Defaults to 180 days if no days specified.
59
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
60
                         Defaults to 30 days if no days specified
58
USAGE
61
USAGE
59
    exit $_[0];
62
    exit $_[0];
60
}
63
}
61
64
62
my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs);
65
my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs, $pSearchhistory);
63
66
64
GetOptions(
67
GetOptions(
65
    'h|help'       => \$help,
68
    'h|help'          => \$help,
66
    'sessions'     => \$sessions,
69
    'sessions'        => \$sessions,
67
    'sessdays:i'   => \$sess_days,
70
    'sessdays:i'      => \$sess_days,
68
    'v|verbose'    => \$verbose,
71
    'v|verbose'       => \$verbose,
69
    'm|mail'       => \$mail,
72
    'm|mail'          => \$mail,
70
    'zebraqueue:i' => \$zebraqueue_days,
73
    'zebraqueue:i'    => \$zebraqueue_days,
71
    'merged'       => \$purge_merged,
74
    'merged'          => \$purge_merged,
72
    'import:i'     => \$pImport,
75
    'import:i'        => \$pImport,
73
    'logs:i'       => \$pLogs,
76
    'logs:i'          => \$pLogs,
77
    'searchhistory:i' => \$pSearchhistory,
74
) || usage(1);
78
) || usage(1);
75
79
76
$sessions=1 if $sess_days && $sess_days>0;
80
$sessions=1 if $sess_days && $sess_days>0;
77
# if --import, --logs or --zebraqueue were passed without number of days,
81
# if --import, --logs, --zebraqueue or --searchhistory were passed without number of days,
78
# use defaults
82
# use defaults
79
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
83
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
80
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
84
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
81
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
85
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
86
$pSearchhistory= DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory==0;
82
87
83
if ($help) {
88
if ($help) {
84
    usage(0);
89
    usage(0);
85
}
90
}
86
91
87
if ( !( $sessions || $zebraqueue_days || $mail || $purge_merged || $pImport || $pLogs) ) {
92
if ( !( $sessions || $zebraqueue_days || $mail || $purge_merged || $pImport || $pLogs || $pSearchhistory ) ) {
88
    print "You did not specify any cleanup work for the script to do.\n\n";
93
    print "You did not specify any cleanup work for the script to do.\n\n";
89
    usage(1);
94
    usage(1);
90
}
95
}
Lines 170-175 if($pLogs) { Link Here
170
    print "Done with purging action_logs.\n" if $verbose;
175
    print "Done with purging action_logs.\n" if $verbose;
171
}
176
}
172
177
178
if($pSearchhistory) {
179
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
180
    $sth = $dbh->prepare("DELETE FROM search_history WHERE time < DATE_SUB( NOW(), INTERVAL ? DAY )");
181
    $sth->execute($pSearchhistory) or die $dbh->errstr;
182
    print "Done with purging search_history.\n" if $verbose;
183
}
184
173
exit(0);
185
exit(0);
174
186
175
sub RemoveOldSessions {
187
sub RemoveOldSessions {
176
- 

Return to bug 10361