Skip to content

Commit 3dfe3c6

Browse files
michieldSam Tuke
authored andcommitted
avoid processing a single bounce twice
1 parent be6bfce commit 3dfe3c6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

public_html/lists/admin/actions/reconcileusers.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,24 @@
6868
$status .= $c.' '.s('subscribers deleted')."<br/>\n";
6969
} elseif ($_GET['option'] == 'relinksystembounces') {
7070
$status = s('Relinking transactional messages that bounced to the related subscriber profile').'<br/ >';
71-
$req = Sql_Query(sprintf('select count(id) from %s where status = "bounced system message" and comment like "%% marked unconfirmed"',$tables['bounce']));
71+
$req = Sql_Query(sprintf('select count(id) from %s b where b.status = "bounced system message" and b.comment like "%% marked unconfirmed" and id not in (select distinct bounce from %s)',$tables['bounce'],$tables['user_message_bounce']));
7272
$totalRow = Sql_Fetch_Row($req);
7373
$total = $totalRow[0];
7474
$status .= s('%d to process',$total).'<br/>';
7575
flush();
7676

7777
$cnt = 0;
7878
$done = 0;
79-
$req = Sql_Query(sprintf('select id,comment,date from %s where status = "bounced system message" and comment like "%% marked unconfirmed"',$tables['bounce']));
79+
$req = Sql_Query(sprintf('select id,comment,date from %s where status = "bounced system message" and comment like "%% marked unconfirmed" and id not in (select distinct bounce from %s)',$tables['bounce'],$tables['user_message_bounce']));
8080
while ($row = Sql_Fetch_Assoc($req)) {
8181
++$cnt;
8282
set_time_limit(60);
8383
if (preg_match('/([\d]+) marked unconfirmed/',$row['comment'],$regs)) {
84-
++$done;
85-
Sql_Query(sprintf('insert into %s (user,message,bounce,time) values(%d,-1,%d,current_timestamp)',$tables['user_message_bounce'],$regs[1],$row['id'],$row['date']));
84+
$exists = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where user = %d and message = -1 and bounce = %d',$tables['user_message_bounce'],$regs[1],$row['id']));
85+
if (empty($exists[0])) {
86+
Sql_Query(sprintf('insert into %s (user,message,bounce,time) values(%d,-1,%d,"%s")',$tables['user_message_bounce'],$regs[1],$row['id'],$row['date']));
87+
++$done;
88+
}
8689
}
8790
}
8891
$status .= s('%d bounces have been associated with a subscriber profile',$done);

0 commit comments

Comments
 (0)