From c53b64d998f3b8af53a5f9e0b7901126765eb789 Mon Sep 17 00:00:00 2001 From: Chris Hood Date: Sun, 3 Apr 2011 13:24:04 +1000 Subject: [PATCH] #970936: update destination address for mail, mimemail, phpmailer & sms when user updates them. --- messaging.module | 10 +++++++ messaging_mail/messaging_mail.module | 25 ++++--------------- messaging_mime_mail/messaging_mime_mail.module | 16 ++++++++++++ messaging_phpmailer/messaging_phpmailer.module | 13 ++++++++++ messaging_sms/messaging_sms.module | 31 ++++++++++++++++++++---- messaging_twitter/messaging_twitter.module | 2 +- 6 files changed, 71 insertions(+), 26 deletions(-) diff --git a/messaging.module b/messaging.module index de88ceb..42acbc0 100644 --- a/messaging.module +++ b/messaging.module @@ -1283,3 +1283,13 @@ function messaging_user_format_name($account, $html = FALSE) { $account = messaging_user_object($account); return $html ? theme('username', $account) : check_plain($account->name); } + +/** + * Update the message destination for a user. + */ +function messaging_update_destination($uid, $type, $destination) { + // Update destination of this user + db_query("UPDATE {messaging_destination} SET address = '%s' WHERE uid = %d AND type = '%s'", $destination, $uid, $type); + // Update uid for destinations with this mail + db_query("UPDATE {messaging_destination} SET uid = %d WHERE uid = 0 AND type = '%s' AND address = '%s'", $uid, $type, $destination); +} diff --git a/messaging_mail/messaging_mail.module b/messaging_mail/messaging_mail.module index 6c758a9..be94124 100644 --- a/messaging_mail/messaging_mail.module +++ b/messaging_mail/messaging_mail.module @@ -76,14 +76,14 @@ function messaging_mail_messaging($op, $type = NULL) { /** * Implementation of hook_user(). - * - * Adds fieldset and default sending method setting. */ -function messaging_mail_user($type, $edit, &$user, $category = NULL) { +function messaging_mail_user($type, $edit, &$account, $category = NULL) { switch ($type) { case 'update': // Claim user mail address if in destinations table - messaging_mail_update_user($user); + if ($account->status && !empty($edit['mail']) && $edit['mail'] != $account->mail) { + messaging_update_destination($account->uid, 'mail', $edit['mail']); + } } } @@ -101,21 +101,6 @@ function messaging_mail_methods() { } /** - * Update destinations when a user account is updated, created - * - * The destinations for that mail account will be assigned to the user - */ -function messaging_mail_update_user($account) { - if ($account->status) { - // Update mail for destinations of this user - db_query("UPDATE {messaging_destination} SET address = '%s' WHERE uid = %d AND type = 'mail'", $account->mail, $account->uid); - // Update uid for destinations with this mail - db_query("UPDATE {messaging_destination} SET uid = %d WHERE uid = 0 AND type = 'mail' AND address = '%s'", $account->uid, $account->mail); - } -} - - -/** * Send mail message to user account * * This is a callback function that will be invoked from messaging delivery methods @@ -141,4 +126,4 @@ function messaging_mail_send_msg($address, $message, $params = array()) { */ function messaging_mail_disable() { messaging_method_disable('mail'); -} \ No newline at end of file +} diff --git a/messaging_mime_mail/messaging_mime_mail.module b/messaging_mime_mail/messaging_mime_mail.module index b71f946..3df6b7e 100644 --- a/messaging_mime_mail/messaging_mime_mail.module +++ b/messaging_mime_mail/messaging_mime_mail.module @@ -46,3 +46,19 @@ function messaging_mime_mail_send_msg($destination, $message, $params) { function messaging_mime_mail_disable() { messaging_method_disable('mimemail'); } + +/** + * Implementation of hook_user(). + * + * Adds fieldset and default sending method setting. + */ +function messaging_mime_mail_user($type, $edit, &$account, $category = NULL) { + switch ($type) { + case 'update': + // Claim user mail address if in destinations table + if ($account->status && !empty($edit['mail']) && $edit['mail'] != $account->mail) { + messaging_update_destination($account->uid, 'mimemail', $edit['mail']); + } + } +} + diff --git a/messaging_phpmailer/messaging_phpmailer.module b/messaging_phpmailer/messaging_phpmailer.module index 18eb233..eac659c 100644 --- a/messaging_phpmailer/messaging_phpmailer.module +++ b/messaging_phpmailer/messaging_phpmailer.module @@ -282,3 +282,16 @@ function theme_messaging_phpmailer($mail) { function messaging_phpmailer_disable() { messaging_method_disable('phpmailer'); } + +/** + * Implementation of hook_user(). + */ +function messaging_mail_user($type, $edit, &$account, $category = NULL) { + switch ($type) { + case 'update': + // Claim user mail address if in destinations table + if ($account->status && !empty($edit['mail']) && $edit['mail'] != $account->mail) { + messaging_update_destination($account->uid, 'phpmailer', $edit['mail']); + } + } +} diff --git a/messaging_sms/messaging_sms.module b/messaging_sms/messaging_sms.module index 09f1607..4d2f5ae 100644 --- a/messaging_sms/messaging_sms.module +++ b/messaging_sms/messaging_sms.module @@ -31,7 +31,6 @@ function messaging_sms_messaging($op = 'info') { 'uid2address callback' => 'messaging_sms_user_destination', //'field_name' => 'uid', // Field on which this address is stored //'field_table' => 'users', // Table on which this address is stored - ); } } @@ -63,9 +62,9 @@ function messaging_sms_user_destination($account) { /** * Send SMS message using the default gateway - * + * * This is just a wrapper for sms_send() - * + * * @param $destination * Mobile phone number */ @@ -73,10 +72,32 @@ function messaging_sms_send_msg($destination, $message, $params = array()) { $text = messaging_text_build($message, ' '); return sms_send($destination, $text, $params); } - + /** * Implementation of hook_disable() */ function messaging_sms_disable() { messaging_method_disable('sms'); -} \ No newline at end of file +} + +/** + * When a new sms number is confirmed update. + */ +function messaging_sms_form_sms_user_settings_confirm_form_alter(&$form, &$form_state) { + $form['#submit'][] = 'messaging_sms_update_user'; +} + +/** + * Update destinations when a user account is updated, created + * + * The destinations for that mail account will be assigned to the user + */ +function messaging_sms_update_user($form, &$form_state) { + $uid = $form_state['values']['uid']; + $account = user_load($uid); + $sms = messaging_sms_user_destination($account); + if ($sms) { + messaging_update_destination($uid, 'sms', $sms); + } +} + diff --git a/messaging_twitter/messaging_twitter.module b/messaging_twitter/messaging_twitter.module index 6b9bf9c..14a9b2c 100644 --- a/messaging_twitter/messaging_twitter.module +++ b/messaging_twitter/messaging_twitter.module @@ -192,4 +192,4 @@ function _messaging_twitter_include() { module_load_include('inc', 'twitter'); $include = TRUE; } -} \ No newline at end of file +} -- 1.7.1