|
68 | 68 | $status .= $c.' '.s('subscribers deleted')."<br/>\n"; |
69 | 69 | } elseif ($_GET['option'] == 'relinksystembounces') { |
70 | 70 | $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'])); |
72 | 72 | $totalRow = Sql_Fetch_Row($req); |
73 | 73 | $total = $totalRow[0]; |
74 | 74 | $status .= s('%d to process',$total).'<br/>'; |
75 | 75 | flush(); |
76 | 76 |
|
77 | 77 | $cnt = 0; |
78 | 78 | $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'])); |
80 | 80 | while ($row = Sql_Fetch_Assoc($req)) { |
81 | 81 | ++$cnt; |
82 | 82 | set_time_limit(60); |
83 | 83 | 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 | + } |
86 | 89 | } |
87 | 90 | } |
88 | 91 | $status .= s('%d bounces have been associated with a subscriber profile',$done); |
|
0 commit comments