Legoktm has submitted this change and it was merged.

Change subject: Ensure that emails are sent to correct email address
......................................................................


Ensure that emails are sent to correct email address

Ensure that the email address associated with non-global requests is the
address from the unattached account rather than any locally attached
account available on the wiki that processes the request.

Bug: T93444
Change-Id: I89e60cab405044d75957552ddd9f671259a0b66a
(cherry picked from commit e355b2976d366e6f766494051765a2af9da6a6fb)
---
M includes/specials/SpecialGlobalRenameQueue.php
1 file changed, 61 insertions(+), 11 deletions(-)

Approvals:
  Legoktm: Verified; Looks good to me, approved



diff --git a/includes/specials/SpecialGlobalRenameQueue.php 
b/includes/specials/SpecialGlobalRenameQueue.php
index af8d9aa..9db7fda 100644
--- a/includes/specials/SpecialGlobalRenameQueue.php
+++ b/includes/specials/SpecialGlobalRenameQueue.php
@@ -372,11 +372,13 @@
        protected function doResolveRequest( $approved, $data ) {
                $request = GlobalRenameRequest::newFromId( $data['rid'] );
                $oldUser = User::newFromName( $request->getName() );
-               // Ensure that oldUser is populated before any possible rename 
occurs
-               // below. Getting the data from cache is as good as from the db 
for
-               // our purposes, so just ensure that an accessor is called to 
unstub
-               // the object.
-               $oldUser->getEmail();
+               if ( $request->userIsGlobal() || $request->getWiki() === 
wfWikiId() ) {
+                       $notifyEmail = MailAddress::newFromUser( $oldUser );
+               } else {
+                       $notifyEmail = $this->getRemoteUserMailAddress(
+                               $request->getWiki(), $request->getName()
+                       );
+               }
                $newUser = User::newFromName( $request->getNewName(), 
'creatable' );
                $status = new Status;
                if ( $approved ) {
@@ -454,18 +456,66 @@
                                        )->inContentLanguage()->text();
                                }
 
-                               $type = $approved ? 'approval' : 'rejection';
-                               wfDebugLog(
-                                       'CentralAuthRename',
-                                       "Sending $type email to 
User:{$oldUser->getName()}/{$oldUser->getEmail()}"
-                               );
-                               $oldUser->sendMail( $subject, $body );
+                               if ( $notifyEmail !== null && 
$notifyEmail->address ) {
+                                       $type = $approved ? 'approval' : 
'rejection';
+                                       wfDebugLog(
+                                               'CentralAuthRename',
+                                               "Sending $type email to 
User:{$oldUser->getName()}/{$notifyEmail->address}"
+                                       );
+                                       $this->sendNotificationEmail( 
$notifyEmail, $subject, $body );
+                               }
                        } else {
                                $status->fatal( 
'globalrenamequeue-request-savefailed' );
                        }
                }
                return $status;
        }
+
+       /**
+        * Get a MailAddress for a user on a remote wiki
+        *
+        * @param string $wiki
+        * @param string $username
+        * @return MailAddress|null
+        */
+       protected function getRemoteUserMailAddress( $wiki, $username ) {
+               $lb = wfGetLB( $wiki );
+               $remoteDB = $lb->getConnection( DB_SLAVE, array(), $wiki );
+               $row = $remoteDB->selectRow(
+                       'user',
+                       array( 'user_email', 'user_name', 'user_real_name' ),
+                       array(
+                               'user_name' => User::getCanonicalName( 
$username ),
+                       ),
+                       __METHOD__
+               );
+               if ( $row === false ) {
+                       $address = null;
+               } else {
+                       $address = new MailAddress(
+                               $row->user_email, $row->user_name, 
$row->user_real_name
+                       );
+               }
+               $lb->reuseConnection( $remoteDB );
+               return $address;
+       }
+
+       /**
+        * Send an email notifying the user of the result of their request.
+        *
+        * @param MailAddress $to
+        * @param string $subject
+        * @param string $body
+        * @return Status
+        */
+       protected function sendNotificationEmail( MailAddress $to, $subject, 
$body ) {
+               global $wgPasswordSender;
+               $from = new MailAddress(
+                       $wgPasswordSender,
+                       wfMessage( 'emailsender' )->inContentLanguage()->text()
+               );
+               return UserMailer::send( $to, $from, $subject, $body );
+       }
 }
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/199046
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I89e60cab405044d75957552ddd9f671259a0b66a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: wmf/1.25wmf21
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to