3 # Copyright 2009 PTFS, Inc.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # find Koha's Perl modules
26 # test carefully before changing this
28 eval { require "$FindBin::Bin/../kohalib.pl" };
40 Usage: $0 [-h|--help] [--sessions] [-v|--verbose] [--zebraqueue DAYS]
41 -h --help prints this help message, and exits, ignoring all other options
42 --sessions purge the sessions table. If you use this while users are logged
43 into Koha, they will have to reconnect.
44 -v --verbose will cause the script to give you a bit more information about the run.
45 --zebraqueue DAYS purge completed entries from the zebraqueue from more than DAYS days ago.
50 my ($help, $sessions, $verbose, $zebraqueue_days);
54 'sessions' => \
$sessions,
55 'v|verbose' => \
$verbose,
56 'zebraqueue:i' => \
$zebraqueue_days,
63 if (!($sessions || $zebraqueue_days)){
64 print "You did not specify any cleanup work for the script to do.\n\n";
68 my $dbh = C4
::Context
->dbh();
76 print "Session purge triggered.\n";
77 $sth = $dbh->prepare("SELECT COUNT(*) FROM sessions");
78 $sth->execute() or die $dbh->errstr;
79 my @count_arr = $sth->fetchrow_array;
80 print "$count_arr[0] entries will be deleted.\n";
82 $sth = $dbh->prepare("TRUNCATE sessions");
83 $sth->execute() or die $dbh->errstr;;
85 print "Done with session purge.\n";
89 if ($zebraqueue_days){
92 print "Zebraqueue purge triggered for $zebraqueue_days days.\n";
94 $sth = $dbh->prepare("SELECT id,biblio_auth_number,server,time FROM zebraqueue
95 WHERE done=1 and time < date_sub(curdate(), interval ? day)");
96 $sth->execute($zebraqueue_days) or die $dbh->errstr;
97 $sth2 = $dbh->prepare("DELETE FROM zebraqueue WHERE id=?");
98 while (my $record = $sth->fetchrow_hashref){
99 $sth2->execute($record->{id
}) or die $dbh->errstr;
103 print "$count records were deleted.\nDone with zebraqueue purge.\n";