Send registration welcome email post-commit
authorGergő Tisza <gtisza@wikimedia.org>
Fri, 19 Aug 2016 06:06:25 +0000 (06:06 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Fri, 19 Aug 2016 07:39:39 +0000 (07:39 +0000)
Follow-up to I8f1bd3e.

Change-Id: I26e7a1857363d4e6627a0f583a8556d0fd8ae623

includes/auth/EmailNotificationSecondaryAuthenticationProvider.php
tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php

index d32640e..a82f018 100644 (file)
@@ -50,15 +50,16 @@ class EmailNotificationSecondaryAuthenticationProvider
                        && $user->getEmail()
                        && !$this->manager->getAuthenticationSessionData( 'no-email' )
                ) {
-                       $status = $user->sendConfirmationMail();
-                       $user->saveSettings();
-                       if ( $status->isGood() ) {
-                               // TODO show 'confirmemail_oncreate' success message
-                       } else {
-                               // TODO show 'confirmemail_sendfailed' error message
-                               $this->logger->warning( 'Could not send confirmation email: ' .
-                                       $status->getWikiText( false, false, 'en' ) );
-                       }
+                       // TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
+                       wfGetDB( DB_MASTER )->onTransactionIdle( function () use ( $user ) {
+                               $user = $user->getInstanceForUpdate();
+                               $status = $user->sendConfirmationMail();
+                               $user->saveSettings();
+                               if ( !$status->isGood() ) {
+                                       $this->logger->warning( 'Could not send confirmation email: ' .
+                                               $status->getWikiText( false, false, 'en' ) );
+                               }
+                       } );
                }
 
                return AuthenticationResponse::newPass();
index 18c46f7..c52c3e9 100644 (file)
@@ -60,19 +60,25 @@ class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit_Fram
                $creator = $this->getMock( 'User' );
                $userWithoutEmail = $this->getMock( 'User' );
                $userWithoutEmail->expects( $this->any() )->method( 'getEmail' )->willReturn( '' );
+               $userWithoutEmail->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf();
                $userWithoutEmail->expects( $this->never() )->method( 'sendConfirmationMail' );
                $userWithEmailError = $this->getMock( 'User' );
                $userWithEmailError->expects( $this->any() )->method( 'getEmail' )->willReturn( 'foo@bar.baz' );
+               $userWithEmailError->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf();
                $userWithEmailError->expects( $this->any() )->method( 'sendConfirmationMail' )
                        ->willReturn( \Status::newFatal( 'fail' ) );
                $userExpectsConfirmation = $this->getMock( 'User' );
                $userExpectsConfirmation->expects( $this->any() )->method( 'getEmail' )
                        ->willReturn( 'foo@bar.baz' );
+               $userExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' )
+                       ->willReturnSelf();
                $userExpectsConfirmation->expects( $this->once() )->method( 'sendConfirmationMail' )
                        ->willReturn( \Status::newGood() );
                $userNotExpectsConfirmation = $this->getMock( 'User' );
                $userNotExpectsConfirmation->expects( $this->any() )->method( 'getEmail' )
                        ->willReturn( 'foo@bar.baz' );
+               $userNotExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' )
+                       ->willReturnSelf();
                $userNotExpectsConfirmation->expects( $this->never() )->method( 'sendConfirmationMail' );
 
                $provider = new EmailNotificationSecondaryAuthenticationProvider( [