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,27 +165,27 @@ 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
$sub = new Subscription(); $user = new User();
$sub->subscribed = $notice->profile_id;
if ($sub->find()) { $user->query('SELECT nickname, smsemail, incomingemail ' .
while ($sub->fetch()) { 'FROM user JOIN subscription ' .
$user = User::staticGet($sub->subscriber); 'ON user.id = subscription.subscriber ' .
if ($user && $user->smsemail && $user->smsnotify) { 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
common_log(LOG_INFO, 'AND user.smsemail IS NOT NULL ' .
'Sending notice ' . $notice->id . ' to ' . $user->smsemail, 'AND user.smsnotify = 1');
__FILE__);
$success = mail_send_sms_notice($notice, $user); while ($user->fetch()) {
if (!$success) { common_log(LOG_INFO,
# XXX: Not sure, but I think that's the right thing to do 'Sending notice ' . $notice->id . ' to ' . $user->smsemail,
common_log(LOG_WARNING, __FILE__);
'Sending notice ' . $notice->id . ' to ' . $user->smsemail . ' FAILED, cancelling.', $success = mail_send_sms_notice_address($notice, $user->smsemail, $user->incomingemail);
__FILE__); if (!$success) {
return false; # XXX: Not sure, but I think that's the right thing to do
} common_log(LOG_WARNING,
} 'Sending notice ' . $notice->id . ' to ' . $user->smsemail . ' FAILED, cancelling.',
__FILE__);
return false;
} }
} }
@ -193,21 +193,24 @@ function mail_broadcast_notice_sms($notice) {
} }
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) {