You can now specify a number of days with the --mail parameter. Only
mails older than the specified number of days will be deleted.
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
use warnings;
use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30;
use warnings;
use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30;
+use constant DEFAULT_MAIL_PURGEDAYS => 30;
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
use constant DEFAULT_LOGS_PURGEDAYS => 180;
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
use constant DEFAULT_LOGS_PURGEDAYS => 180;
about the run.
--zebraqueue DAYS purge completed zebraqueue entries older than DAYS days.
Defaults to 30 days if no days specified.
about the run.
--zebraqueue DAYS purge completed zebraqueue entries older than DAYS days.
Defaults to 30 days if no days specified.
- -m --mail purge the mail queue.
+ -m --mail DAYS purge items from the mail queue that are older than DAYS days.
+ Defaults to 30 days if no days specified.
--merged purged completed entries from need_merge_authorities.
--import DAYS purge records from import tables older than DAYS days.
Defaults to 60 days if no days specified.
--merged purged completed entries from need_merge_authorities.
--import DAYS purge records from import tables older than DAYS days.
Defaults to 60 days if no days specified.
'sessions' => \$sessions,
'sessdays:i' => \$sess_days,
'v|verbose' => \$verbose,
'sessions' => \$sessions,
'sessdays:i' => \$sess_days,
'v|verbose' => \$verbose,
'zebraqueue:i' => \$zebraqueue_days,
'merged' => \$purge_merged,
'import:i' => \$pImport,
'zebraqueue:i' => \$zebraqueue_days,
'merged' => \$purge_merged,
'import:i' => \$pImport,
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
$pImport= DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport==0;
$pLogs= DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs==0;
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
+$mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0;
- if ($verbose) {
- $sth = $dbh->prepare("SELECT COUNT(*) FROM message_queue");
- $sth->execute() or die $dbh->errstr;
- my @count_arr = $sth->fetchrow_array;
- print "Deleting $count_arr[0] entries from the mail queue.\n";
- }
- $sth = $dbh->prepare("TRUNCATE message_queue");
- $sth->execute() or $dbh->errstr;
- print "Done with purging the mail queue.\n" if ($verbose);
+ 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);