From e4502fa12073ca33717b4aa5d1cece4f7afb4371 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 1 Jul 2011 22:11:22 +0200 Subject: [PATCH] Add a safeguard preventing to send a given NL to a given user more than once. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/newsletter.inc.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 447c7b7..3359249 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -361,7 +361,7 @@ class NewsLetter } if (self::maySubscribe($user)) { XDB::execute('INSERT IGNORE INTO newsletter_ins (nlid, uid, last, hash) - VALUES ({?}, {?}, NULL, hash)', + VALUES ({?}, {?}, 0, hash)', $this->id, $user->id()); } } @@ -1190,20 +1190,23 @@ class NLIssue $this->id); $ufc = new PFC_And($this->getRecipientsUFC(), new UFC_NLSubscribed($this->nl->id, $this->id), new UFC_HasValidEmail()); - $emailsCount = 0; $uf = new UserFilter($ufc, array(new UFO_IsAdmin(), new UFO_Uid())); $limit = new PlLimit(self::BATCH_SIZE); + $global_sent = array(); while (true) { $sent = array(); $users = $uf->getUsers($limit); if (count($users) == 0) { - return $emailsCount; + break; } foreach ($users as $user) { + if (array_key_exists($user->id(), $global_sent)) { + Platal::kill('Sending the same newsletter issue ' . $this->id . ' to user ' . $user->id() . ' twice, something must be wrong.'); + } $sent[] = $user->id(); + $global_sent[$user->id()] = true; $this->sendTo($user, $hash); - ++$emailsCount; } XDB::execute("UPDATE newsletter_ins SET last = {?} @@ -1211,7 +1214,7 @@ class NLIssue sleep(60); } - return $emailsCount; + return count($global_sent); } // }}} -- 2.1.4