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]
42 -h --help prints this help message, and exits, ignoring all
44 --sessions purge the sessions table. If you use this while users
45 are logged into Koha, they will have to reconnect.
46 -v --verbose will cause the script to give you a bit more information
48 --zebraqueue DAYS purge completed entries from the zebraqueue from
49 more than DAYS days ago.
50 -m --mail purge the mail queue.
55 my ($help, $sessions, $verbose, $zebraqueue_days, $mail);
59 'sessions' => \$sessions,
60 'v|verbose' => \$verbose,
62 'zebraqueue:i' => \$zebraqueue_days,
69 if (!($sessions || $zebraqueue_days || $mail)){
70 print "You did not specify any cleanup work for the script to do.\n\n";
74 my $dbh = C4::Context->dbh();
82 print "Session purge triggered.\n";
83 $sth = $dbh->prepare("SELECT COUNT(*) FROM sessions");
84 $sth->execute() or die $dbh->errstr;
85 my @count_arr = $sth->fetchrow_array;
86 print "$count_arr[0] entries will be deleted.\n";
88 $sth = $dbh->prepare("TRUNCATE sessions");
89 $sth->execute() or die $dbh->errstr;;
91 print "Done with session purge.\n";
95 if ($zebraqueue_days){
98 print "Zebraqueue purge triggered for $zebraqueue_days days.\n";
100 $sth = $dbh->prepare("SELECT id,biblio_auth_number,server,time FROM zebraqueue
101 WHERE done=1 and time < date_sub(curdate(), interval ? day)");
102 $sth->execute($zebraqueue_days) or die $dbh->errstr;
103 $sth2 = $dbh->prepare("DELETE FROM zebraqueue WHERE id=?");
104 while (my $record = $sth->fetchrow_hashref){
105 $sth2->execute($record->{id}) or die $dbh->errstr;
109 print "$count records were deleted.\nDone with zebraqueue purge.\n";
115 $sth = $dbh->prepare("SELECT COUNT(*) FROM message_queue");
116 $sth->execute() or die $dbh->errstr;
117 my @count_arr = $sth->fetchrow_array;
118 print "Deleting $count_arr[0] entries from the mail queue.\n";
120 $sth = $dbh->prepare("TRUNCATE message_queue");
121 $sth->execute() or $dbh->errstr;
122 print "Done with purging the mail queue.\n" if ($verbose);