change sms broadcast to use a join

darcs-hash:20080905022019-84dde-d53b1dda2cd0ec996b8dda99a00d01e6da000d3f.gz
This commit is contained in:
Evan Prodromou 2008-09-04 22:20:19 -04:00
parent d17cb8eedc
commit 96de63ea99
1 changed files with 33 additions and 30 deletions

View File

@ -165,49 +165,52 @@ function mail_new_incoming_address() {
function mail_broadcast_notice_sms($notice) { function mail_broadcast_notice_sms($notice) {
# Now, get users subscribed to this profile # Now, get users subscribed to this profile
# XXX: use a join here rather than looping through results
$user = new User();
$sub = new Subscription();
$sub->subscribed = $notice->profile_id; $user->query('SELECT nickname, smsemail, incomingemail ' .
'FROM user JOIN subscription ' .
if ($sub->find()) { 'ON user.id = subscription.subscriber ' .
while ($sub->fetch()) { 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
$user = User::staticGet($sub->subscriber); 'AND user.smsemail IS NOT NULL ' .
if ($user && $user->smsemail && $user->smsnotify) { 'AND user.smsnotify = 1');
common_log(LOG_INFO,
'Sending notice ' . $notice->id . ' to ' . $user->smsemail, while ($user->fetch()) {
__FILE__); common_log(LOG_INFO,
$success = mail_send_sms_notice($notice, $user); 'Sending notice ' . $notice->id . ' to ' . $user->smsemail,
if (!$success) { __FILE__);
# XXX: Not sure, but I think that's the right thing to do $success = mail_send_sms_notice_address($notice, $user->smsemail, $user->incomingemail);
common_log(LOG_WARNING, if (!$success) {
'Sending notice ' . $notice->id . ' to ' . $user->smsemail . ' FAILED, cancelling.', # XXX: Not sure, but I think that's the right thing to do
__FILE__); common_log(LOG_WARNING,
return false; 'Sending notice ' . $notice->id . ' to ' . $user->smsemail . ' FAILED, cancelling.',
} __FILE__);
} return false;
} }
} }
return true; return true;
} }
function mail_send_sms_notice($notice, $user) { function mail_send_sms_notice($notice, $user) {
$profile = $user->getProfile(); return mail_send_sms_notice_address($notice, $user->smsemail, $user->incomingemail);
$name = $profile->getBestName(); }
$to = $name . ' <' . $user->smsemail . '>';
function mail_send_sms_notice_address($notice, $smsemail, $incomingemail) {
$to = $nickname . ' <' . $smsemail . '>';
$other = $notice->getProfile(); $other = $notice->getProfile();
common_log(LOG_INFO, "Sending notice " . $notice->id . " to " . $user->smsemail, __FILE__); common_log(LOG_INFO, "Sending notice " . $notice->id . " to " . $smsemail, __FILE__);
$headers = array(); $headers = array();
$headers['From'] = (isset($user->incomingemail)) ? $user->incomingemail : mail_notify_from(); $headers['From'] = (isset($incomingemail)) ? $incomingemail : mail_notify_from();
$headers['To'] = $to; $headers['To'] = $to;
$headers['Subject'] = sprintf(_('%s status'), $headers['Subject'] = sprintf(_('%s status'),
$other->getBestName()); $other->getBestName());
$body = $notice->content; $body = $notice->content;
return mail_send($user->smsemail, $headers, $body); return mail_send($smsemail, $headers, $body);
} }
function mail_confirm_sms($code, $nickname, $address) { function mail_confirm_sms($code, $nickname, $address) {