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

(-)a/C4/Search.pm (-1 / +8 lines)
Lines 71-77 This module provides searching functions for Koha's bibliographic databases Link Here
71
  &AddSearchHistory
71
  &AddSearchHistory
72
  &GetDistinctValues
72
  &GetDistinctValues
73
  &enabled_staff_search_views
73
  &enabled_staff_search_views
74
  &SimpleSearch
74
  &PurgeSearchHistory
75
);
75
);
76
76
77
# make all your functions, whether exported or not;
77
# make all your functions, whether exported or not;
Lines 2217-2222 sub GetSearchHistory{ Link Here
2217
    return  $sth->fetchall_hashref({});
2217
    return  $sth->fetchall_hashref({});
2218
}
2218
}
2219
2219
2220
sub PurgeSearchHistory{
2221
    my ($pSearchhistory)=@_;
2222
    my $dbh = C4::Context->dbh;
2223
    my $sth = $dbh->prepare("DELETE FROM search_history WHERE time < DATE_SUB( NOW(), INTERVAL ? DAY )");
2224
    $sth->execute($pSearchhistory) or die $dbh->errstr;
2225
}
2226
2220
=head2 z3950_search_args
2227
=head2 z3950_search_args
2221
2228
2222
$arrayref = z3950_search_args($matchpoints)
2229
$arrayref = z3950_search_args($matchpoints)
(-)a/misc/cronjobs/cleanup_database.pl (-30 / +42 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 34-90 BEGIN { Link Here
34
use C4::Context;
35
use C4::Context;
35
use C4::Dates;
36
use C4::Dates;
36
37
38
use C4::Search;
39
37
use Getopt::Long;
40
use Getopt::Long;
38
41
39
sub usage {
42
sub usage {
40
    print STDERR <<USAGE;
43
    print STDERR <<USAGE;
41
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS]
44
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS]
42
45
43
   -h --help          prints this help message, and exits, ignoring all
46
   -h --help             prints this help message, and exits, ignoring all
44
                      other options
47
                         other options
45
   --sessions         purge the sessions table.  If you use this while users 
48
   --sessions            purge the sessions table.  If you use this while users
46
                      are logged into Koha, they will have to reconnect.
49
                         are logged into Koha, they will have to reconnect.
47
   --sessdays DAYS    purge only sessions older than DAYS days.
50
   --sessdays DAYS       purge only sessions older than DAYS days.
48
   -v --verbose       will cause the script to give you a bit more information
51
   -v --verbose          will cause the script to give you a bit more information
49
                      about the run.
52
                         about the run.
50
   --zebraqueue DAYS  purge completed zebraqueue entries older than DAYS days.
53
   --zebraqueue DAYS     purge completed zebraqueue entries older than DAYS days.
51
                      Defaults to 30 days if no days specified.
54
                         Defaults to 30 days if no days specified.
52
   -m --mail          purge the mail queue. 
55
   -m --mail             purge the mail queue.
53
   --merged           purged completed entries from need_merge_authorities.
56
   --merged              purged completed entries from need_merge_authorities.
54
   --import DAYS      purge records from import tables older than DAYS days.
57
   --import DAYS         purge records from import tables older than DAYS days.
55
                      Defaults to 60 days if no days specified.
58
                         Defaults to 60 days if no days specified.
56
   --logs DAYS        purge entries from action_logs older than DAYS days.
59
   --logs DAYS           purge entries from action_logs older than DAYS days.
57
                      Defaults to 180 days if no days specified.
60
                         Defaults to 180 days if no days specified.
61
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
62
                         Defaults to 30 days if no days specified
58
USAGE
63
USAGE
59
    exit $_[0];
64
    exit $_[0];
60
}
65
}
61
66
62
my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs);
67
my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs, $pSearchhistory);
63
68
64
GetOptions(
69
GetOptions(
65
    'h|help'       => \$help,
70
    'h|help'          => \$help,
66
    'sessions'     => \$sessions,
71
    'sessions'        => \$sessions,
67
    'sessdays:i'   => \$sess_days,
72
    'sessdays:i'      => \$sess_days,
68
    'v|verbose'    => \$verbose,
73
    'v|verbose'       => \$verbose,
69
    'm|mail'       => \$mail,
74
    'm|mail'          => \$mail,
70
    'zebraqueue:i' => \$zebraqueue_days,
75
    'zebraqueue:i'    => \$zebraqueue_days,
71
    'merged'       => \$purge_merged,
76
    'merged'          => \$purge_merged,
72
    'import:i'     => \$pImport,
77
    'import:i'        => \$pImport,
73
    'logs:i'       => \$pLogs,
78
    'logs:i'          => \$pLogs,
79
    'searchhistory:i' => \$pSearchhistory,
74
) || usage(1);
80
) || usage(1);
75
81
76
$sessions=1 if $sess_days && $sess_days>0;
82
$sessions=1 if $sess_days && $sess_days>0;
77
# if --import, --logs or --zebraqueue were passed without number of days,
83
# if --import, --logs, --zebraqueue or --searchhistory were passed without number of days,
78
# use defaults
84
# use defaults
79
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
85
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
80
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
86
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
81
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
87
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
88
$pSearchhistory= DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory==0;
82
89
83
if ($help) {
90
if ($help) {
84
    usage(0);
91
    usage(0);
85
}
92
}
86
93
87
if ( !( $sessions || $zebraqueue_days || $mail || $purge_merged || $pImport || $pLogs) ) {
94
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";
95
    print "You did not specify any cleanup work for the script to do.\n\n";
89
    usage(1);
96
    usage(1);
90
}
97
}
Lines 170-175 if($pLogs) { Link Here
170
    print "Done with purging action_logs.\n" if $verbose;
177
    print "Done with purging action_logs.\n" if $verbose;
171
}
178
}
172
179
180
if($pSearchhistory) {
181
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
182
    PurgeSearchHistory($pSearchhistory);
183
    print "Done with purging search_history.\n" if $verbose;
184
}
185
173
exit(0);
186
exit(0);
174
187
175
sub RemoveOldSessions {
188
sub RemoveOldSessions {
176
- 

Return to bug 10361