Lines 73-79
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
Link Here
|
73 |
Defaults to 30 days if no days specified. |
73 |
Defaults to 30 days if no days specified. |
74 |
--keep-lc LC[,LC]* only used in conjunction with -m/--mail. |
74 |
--keep-lc LC[,LC]* only used in conjunction with -m/--mail. |
75 |
Keeps certain emails in the message_queue based on a |
75 |
Keeps certain emails in the message_queue based on a |
76 |
comma-separated list of LETTER_CODES |
76 |
comma-separated list of letter_id |
77 |
--merged purged completed entries from need_merge_authorities. |
77 |
--merged purged completed entries from need_merge_authorities. |
78 |
--messages DAYS purge entries from messages table older than DAYS days. |
78 |
--messages DAYS purge entries from messages table older than DAYS days. |
79 |
Defaults to 365 days if no days specified. |
79 |
Defaults to 365 days if no days specified. |
Lines 135-141
my $sess_days;
Link Here
|
135 |
my $verbose; |
135 |
my $verbose; |
136 |
my $zebraqueue_days; |
136 |
my $zebraqueue_days; |
137 |
my $mail; |
137 |
my $mail; |
138 |
my $letter_codes; |
138 |
my $letter_id; |
139 |
my $purge_merged; |
139 |
my $purge_merged; |
140 |
my $pImport; |
140 |
my $pImport; |
141 |
my $pLogs; |
141 |
my $pLogs; |
Lines 180-186
GetOptions(
Link Here
|
180 |
'sessdays:i' => \$sess_days, |
180 |
'sessdays:i' => \$sess_days, |
181 |
'v|verbose' => \$verbose, |
181 |
'v|verbose' => \$verbose, |
182 |
'm|mail:i' => \$mail, |
182 |
'm|mail:i' => \$mail, |
183 |
'keep-lc:s' => \$letter_codes, |
183 |
'keep-lc:s' => \$letter_id, |
184 |
'zebraqueue:i' => \$zebraqueue_days, |
184 |
'zebraqueue:i' => \$zebraqueue_days, |
185 |
'merged' => \$purge_merged, |
185 |
'merged' => \$purge_merged, |
186 |
'import:i' => \$pImport, |
186 |
'import:i' => \$pImport, |
Lines 286-296
say "Confirm flag not passed, running in dry-run mode..." unless $confirm;
Link Here
|
286 |
|
286 |
|
287 |
cronlogaction({ info => $command_line_options }); |
287 |
cronlogaction({ info => $command_line_options }); |
288 |
|
288 |
|
289 |
if (!$mail && $letter_codes) { |
|
|
290 |
print "You should not specify --keep-lc if you're not cleaning emails.\n\n"; |
291 |
usage(1); |
292 |
} |
293 |
|
294 |
my $dbh = C4::Context->dbh(); |
289 |
my $dbh = C4::Context->dbh(); |
295 |
my $sth; |
290 |
my $sth; |
296 |
my $sth2; |
291 |
my $sth2; |
Lines 344-365
if ($zebraqueue_days) {
Link Here
|
344 |
if ($mail) { |
339 |
if ($mail) { |
345 |
my $count = 0; |
340 |
my $count = 0; |
346 |
print "Mail queue purge triggered for $mail days.\n" if $verbose; |
341 |
print "Mail queue purge triggered for $mail days.\n" if $verbose; |
347 |
print "Not deleting emails of type $letter_codes.\n" if ($verbose && $letter_codes); |
342 |
print "Not deleting emails of type $letter_id.\n" if ($verbose && $letter_id); |
348 |
my (@codes, $quoted_codes); |
343 |
my $query = q{ |
349 |
if ($letter_codes) { |
344 |
DELETE FROM message_queue |
350 |
$letter_codes =~ s/ //g; |
345 |
WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY) |
351 |
@codes = map { "$_" } split(',', $letter_codes); |
346 |
}; |
352 |
$quoted_codes = join ",", ("?") x @codes; |
347 |
my @bind_params = ($mail); |
353 |
} |
348 |
if ($letter_id) { |
354 |
|
349 |
$letter_id =~ s/ //g; |
355 |
$sth = $dbh->prepare(" |
350 |
my @codes = map { "$_" } split(',', $letter_id); |
356 |
DELETE FROM message_queue |
351 |
$query .= " AND letter_id NOT IN ( ".(join ",", ("?") x @codes)." )"; |
357 |
WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY) |
352 |
push @bind_params, @codes; |
358 |
AND letter_code NOT IN ( $quoted_codes )"); |
353 |
} |
359 |
$sth->execute($mail, @codes) or die $dbh->errstr; |
354 |
$sth = $dbh->prepare($query); |
360 |
$count = $sth->rows; |
355 |
if ( $confirm ) { |
361 |
$sth->finish; |
356 |
$sth->execute(@bind_params) or die $dbh->errstr; |
362 |
print "$count messages were deleted from the mail queue.\nDone with message_queue purge.\n" if $verbose; |
357 |
$count = $sth->rows; |
|
|
358 |
} |
359 |
if ( $verbose ) { |
360 |
say $confirm ? "$count messages were deleted from the mail queue." : "Message from message_queue would have been deleted"; |
361 |
say "Done with message_queue purge."; |
362 |
} |
363 |
} |
363 |
} |
364 |
|
364 |
|
365 |
if ($purge_merged) { |
365 |
if ($purge_merged) { |
366 |
- |
|
|