From: Gergő Tisza Date: Fri, 19 Aug 2016 06:06:25 +0000 (+0000) Subject: Send registration welcome email post-commit X-Git-Tag: 1.31.0-rc.0~5990^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=97ad2ba55e4a612a2178bb9abecabf1a488ccf57;p=lhc%2Fweb%2Fwiklou.git Send registration welcome email post-commit Follow-up to I8f1bd3e. Change-Id: I26e7a1857363d4e6627a0f583a8556d0fd8ae623 --- diff --git a/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php b/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php index d32640ea1d..a82f018d48 100644 --- a/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php +++ b/includes/auth/EmailNotificationSecondaryAuthenticationProvider.php @@ -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(); diff --git a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php index 18c46f7cc5..c52c3e9f54 100644 --- a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php @@ -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( [