+ print "Mail queue purge triggered for $mail days.\n" if ($verbose);
+
+ $sth = $dbh->prepare("DELETE FROM message_queue WHERE time_queued < date_sub(curdate(), interval ? day)");
+ $sth->execute($mail) or die $dbh->errstr;
+ my $count = $sth->rows;
+ $sth->finish;
+
+ print "$count messages were deleted from the mail queue.\nDone with message_queue purge.\n" if ($verbose);
+}
+
+if($purge_merged) {
+ print "Purging completed entries from need_merge_authorities.\n" if $verbose;
+ $sth = $dbh->prepare("DELETE FROM need_merge_authorities WHERE done=1");
+ $sth->execute() or die $dbh->errstr;
+ print "Done with purging need_merge_authorities.\n" if $verbose;
+}
+
+if($pImport) {
+ print "Purging records from import tables.\n" if $verbose;
+ PurgeImportTables();
+ print "Done with purging import tables.\n" if $verbose;
+}
+
+if($pZ3950) {
+ print "Purging Z39.50 records from import tables.\n" if $verbose;
+ PurgeZ3950();
+ print "Done with purging Z39.50 records from import tables.\n" if $verbose;
+}
+
+if($pLogs) {
+ print "Purging records from action_logs.\n" if $verbose;
+ $sth = $dbh->prepare("DELETE FROM action_logs WHERE timestamp < date_sub(curdate(), interval ? DAY)");
+ $sth->execute($pLogs) or die $dbh->errstr;
+ print "Done with purging action_logs.\n" if $verbose;
+}
+
+if($pSearchhistory) {
+ print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
+ PurgeSearchHistory($pSearchhistory);
+ print "Done with purging search_history.\n" if $verbose;
+}
+
+if ($pListShareInvites) {
+ print "Purging unaccepted list share invites older than $pListShareInvites days.\n" if $verbose;
+ $sth = $dbh->prepare("
+ DELETE FROM virtualshelfshares
+ WHERE invitekey IS NOT NULL
+ AND (sharedate + INTERVAL ? DAY) < NOW()
+ ");
+ $sth->execute($pListShareInvites);
+ print "Done with purging unaccepted list share invites.\n" if $verbose;
+}
+
+exit(0);
+
+sub RemoveOldSessions {
+ my ( $id, $a_session, $limit, $lasttime );
+ $limit = time() - 24 * 3600 * $sess_days;
+
+ $sth = $dbh->prepare("SELECT id, a_session FROM sessions");
+ $sth->execute or die $dbh->errstr;
+ $sth->bind_columns( \$id, \$a_session );
+ $sth2 = $dbh->prepare("DELETE FROM sessions WHERE id=?");
+ $count = 0;
+
+ while ( $sth->fetch ) {
+ $lasttime = 0;
+ if ( $a_session =~ /lasttime:\s+'?(\d+)/ ) {
+ $lasttime = $1;
+ } elsif ( $a_session =~ /(ATIME|CTIME):\s+'?(\d+)/ ) {
+ $lasttime = $2;
+ }
+ if ( $lasttime && $lasttime < $limit ) {
+ $sth2->execute($id) or die $dbh->errstr;
+ $count++;
+ }
+ }