Unverified Commit 2641dbd9 by Scott Committed by GitHub

Merge pull request #657 from pupi1985/patch-109

Avoid sending emails to blocked and unapproved users
parents 1c7e3713 306a9bec
......@@ -59,10 +59,14 @@ function qa_mailing_stop()
function qa_mailing_perform_step()
{
require_once QA_INCLUDE_DIR . 'db/users.php';
require_once QA_INCLUDE_DIR . 'app/users.php';
$lastuserid = qa_opt('mailing_last_userid');
if (strlen($lastuserid)) {
if (strlen($lastuserid) == 0) {
return;
}
$thistime = time();
$lasttime = qa_opt('mailing_last_timestamp');
$perminute = qa_opt('mailing_per_minute');
......@@ -74,7 +78,10 @@ function qa_mailing_perform_step()
$count = min(floor(($thistime - $lasttime) * $perminute / 60), 100); // don't do more than 100 messages at a time
if ($count > 0) {
if ($count == 0) {
return;
}
qa_opt('mailing_last_timestamp', $thistime + 30);
// prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex)
......@@ -89,19 +96,24 @@ function qa_mailing_perform_step()
qa_opt('mailing_last_userid', $lastuserid);
qa_opt('mailing_done_users', qa_opt('mailing_done_users') + count($users));
$isModeratingUsers = qa_opt('moderate_users');
foreach ($users as $user) {
if (!($user['flags'] & QA_USER_FLAGS_NO_MAILINGS)) {
if (($user['flags'] & QA_USER_FLAGS_NO_MAILINGS) || // exclude users who don't want to get the mailings
($user['flags'] & QA_USER_FLAGS_USER_BLOCKED) || // exclude blocked users
($isModeratingUsers && ($user['level'] < QA_USER_LEVEL_APPROVED))) { // if moderating users exclude unapproved users
continue;
}
qa_mailing_send_one($user['userid'], $user['handle'], $user['email'], $user['emailcode']);
$sentusers++;
}
}
qa_opt('mailing_last_timestamp', $lasttime + $sentusers * 60 / $perminute); // can be floating point result, based on number of mails actually sent
} else
} else {
qa_mailing_stop();
}
}
}
......
......@@ -376,7 +376,7 @@ function qa_db_user_levels_set($userid, $userlevels)
function qa_db_users_get_mailing_next($lastuserid, $count)
{
return qa_db_read_all_assoc(qa_db_query_sub(
'SELECT userid, email, handle, emailcode, flags FROM ^users WHERE userid># ORDER BY userid LIMIT #',
'SELECT userid, email, handle, emailcode, flags, level FROM ^users WHERE userid># ORDER BY userid LIMIT #',
$lastuserid, $count
));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment