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 (-5 / +17 lines)
Lines 24-29 use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30; Link Here
24
use constant DEFAULT_MAIL_PURGEDAYS => 30;
24
use constant DEFAULT_MAIL_PURGEDAYS => 30;
25
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
25
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
26
use constant DEFAULT_LOGS_PURGEDAYS => 180;
26
use constant DEFAULT_LOGS_PURGEDAYS => 180;
27
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30;
27
28
28
BEGIN {
29
BEGIN {
29
    # find Koha's Perl modules
30
    # find Koha's Perl modules
Lines 35-45 BEGIN { Link Here
35
use C4::Context;
36
use C4::Context;
36
use C4::Dates;
37
use C4::Dates;
37
38
39
use C4::Search;
40
38
use Getopt::Long;
41
use Getopt::Long;
39
42
40
sub usage {
43
sub usage {
41
    print STDERR <<USAGE;
44
    print STDERR <<USAGE;
42
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS]
45
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS]
43
46
44
   -h --help          prints this help message, and exits, ignoring all
47
   -h --help          prints this help message, and exits, ignoring all
45
                      other options
48
                      other options
Lines 57-67 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
57
                      Defaults to 60 days if no days specified.
60
                      Defaults to 60 days if no days specified.
58
   --logs DAYS        purge entries from action_logs older than DAYS days.
61
   --logs DAYS        purge entries from action_logs older than DAYS days.
59
                      Defaults to 180 days if no days specified.
62
                      Defaults to 180 days if no days specified.
63
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
64
                         Defaults to 30 days if no days specified
60
USAGE
65
USAGE
61
    exit $_[0];
66
    exit $_[0];
62
}
67
}
63
68
64
my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs);
69
my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs, $pSearchhistory);
65
70
66
GetOptions(
71
GetOptions(
67
    'h|help'       => \$help,
72
    'h|help'       => \$help,
Lines 73-93 GetOptions( Link Here
73
    'merged'       => \$purge_merged,
78
    'merged'       => \$purge_merged,
74
    'import:i'     => \$pImport,
79
    'import:i'     => \$pImport,
75
    'logs:i'       => \$pLogs,
80
    'logs:i'       => \$pLogs,
81
    'searchhistory:i' => \$pSearchhistory,
76
) || usage(1);
82
) || usage(1);
77
83
78
$sessions=1 if $sess_days && $sess_days>0;
84
$sessions=1 if $sess_days && $sess_days>0;
79
# if --import, --logs or --zebraqueue were passed without number of days,
85
# if --import, --logs, --zebraqueue or --searchhistory were passed without number of days,
80
# use defaults
86
# use defaults
81
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
87
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
82
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
88
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
83
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
89
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
84
$mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0;
90
$mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0;
91
$pSearchhistory= DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory==0;
85
92
86
if ($help) {
93
if ($help) {
87
    usage(0);
94
    usage(0);
88
}
95
}
89
96
90
if ( !( $sessions || $zebraqueue_days || $mail || $purge_merged || $pImport || $pLogs) ) {
97
if ( !( $sessions || $zebraqueue_days || $mail || $purge_merged || $pImport || $pLogs || $pSearchhistory ) ) {
91
    print "You did not specify any cleanup work for the script to do.\n\n";
98
    print "You did not specify any cleanup work for the script to do.\n\n";
92
    usage(1);
99
    usage(1);
93
}
100
}
Lines 172-177 if($pLogs) { Link Here
172
    print "Done with purging action_logs.\n" if $verbose;
179
    print "Done with purging action_logs.\n" if $verbose;
173
}
180
}
174
181
182
if($pSearchhistory) {
183
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
184
    PurgeSearchHistory($pSearchhistory);
185
    print "Done with purging search_history.\n" if $verbose;
186
}
187
175
exit(0);
188
exit(0);
176
189
177
sub RemoveOldSessions {
190
sub RemoveOldSessions {
178
- 

Return to bug 10361