From: Raphaël Barrois Date: Fri, 1 Jul 2011 20:11:22 +0000 (+0200) Subject: Add a safeguard preventing to send a given NL to a given user more than once. X-Git-Tag: xorg/1.1.3~2^2~7 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e4502fa12073ca33717b4aa5d1cece4f7afb4371;p=platal.git Add a safeguard preventing to send a given NL to a given user more than once. Signed-off-by: Raphaël Barrois --- 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); } // }}}