jenkins-bot has submitted this change and it was merged. Change subject: Make CentralAuthHooks::onLocalUserCreated() trigger importLocalNames() ......................................................................
Make CentralAuthHooks::onLocalUserCreated() trigger importLocalNames() The update will be done post-send to avoid blocking the client. This avoids having the import randomly happen on HTTP GET. Bug: T92357 Change-Id: I769a75512fc523da94377098567b53d23a03cc38 --- M includes/CentralAuthHooks.php M includes/CentralAuthPrimaryAuthenticationProvider.php M includes/CentralAuthUser.php M includes/CentralAuthUtils.php M includes/LocalRenameJob/LocalPageMoveJob.php M includes/specials/SpecialCentralAutoLogin.php 6 files changed, 25 insertions(+), 14 deletions(-) Approvals: Gergő Tisza: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/CentralAuthHooks.php b/includes/CentralAuthHooks.php index eb6366a..81df7ff 100644 --- a/includes/CentralAuthHooks.php +++ b/includes/CentralAuthHooks.php @@ -279,9 +279,11 @@ if ( !$centralUser->exists() && !$centralUser->listUnattached() ) { if ( $centralUser->register( null, $user->getEmail() ) ) { $centralUser->attach( wfWikiID(), 'new' ); - CentralAuthUtils::getCentralDB()->onTransactionIdle( function () use ( $centralUser ) { - CentralAuthUtils::scheduleCreationJobs( $centralUser ); - } ); + CentralAuthUtils::getCentralDB()->onTransactionIdle( + function () use ( $centralUser ) { + CentralAuthUtils::scheduleCreationJobs( $centralUser ); + } + ); } } diff --git a/includes/CentralAuthPrimaryAuthenticationProvider.php b/includes/CentralAuthPrimaryAuthenticationProvider.php index 1f5d158..4b87861 100644 --- a/includes/CentralAuthPrimaryAuthenticationProvider.php +++ b/includes/CentralAuthPrimaryAuthenticationProvider.php @@ -448,6 +448,10 @@ public function finishAccountCreation( $user, $creator, AuthenticationResponse $response ) { $centralUser = CentralAuthUser::getMasterInstance( $user ); + // Populate the table of local users with this name post-send (if not done already) + DeferredUpdates::addCallableUpdate( function () use ( $centralUser ) { + $centralUser->lazyImportLocalNames(); + } ); // Do the attach in finishAccountCreation instead of begin because now the user has been added // to database and local ID exists (which is needed in attach) $centralUser->attach( wfWikiID(), 'new' ); diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php index 7a7b836..b2859e1 100644 --- a/includes/CentralAuthUser.php +++ b/includes/CentralAuthUser.php @@ -748,7 +748,7 @@ * @param $email String * @return bool */ - function register( $password, $email ) { + public function register( $password, $email ) { $this->checkWriteMode(); $dbw = CentralAuthUtils::getCentralDB(); list( $salt, $hash ) = $this->saltedPassword( $password ); @@ -1831,6 +1831,7 @@ $engine->send( $rc, $formatter->getLine( $userpage, $wikiID ) ); } } + } /** @@ -2082,7 +2083,7 @@ /** * @return bool */ - function lazyImportLocalNames() { + public function lazyImportLocalNames() { $known = (bool)CentralAuthUtils::getCentralSlaveDB()->selectField( 'globalnames', '1', [ 'gn_name' => $this->mName ], __METHOD__ ); @@ -2101,7 +2102,7 @@ * * @return Bool whether any results were found */ - function importLocalNames() { + protected function importLocalNames() { $rows = []; foreach ( self::getWikiList() as $wikiID ) { $dbr = wfGetLB( $wikiID )->getConnectionRef( DB_REPLICA, array(), $wikiID ); diff --git a/includes/CentralAuthUtils.php b/includes/CentralAuthUtils.php index 04d905f..e4b9367 100644 --- a/includes/CentralAuthUtils.php +++ b/includes/CentralAuthUtils.php @@ -266,7 +266,7 @@ Title::makeTitleSafe( NS_USER, $name ), array( 'name' => $name, 'from' => $thisWiki, 'session' => $session ) ); - JobQueueGroup::singleton( $wiki )->push( $job ); + JobQueueGroup::singleton( $wiki )->lazyPush( $job ); } } } diff --git a/includes/LocalRenameJob/LocalPageMoveJob.php b/includes/LocalRenameJob/LocalPageMoveJob.php index 3af8d53..8568eac 100644 --- a/includes/LocalRenameJob/LocalPageMoveJob.php +++ b/includes/LocalRenameJob/LocalPageMoveJob.php @@ -58,7 +58,7 @@ $mp = new MovePage( $oldPage, $newPage ); $valid = $mp->isValidMove(); if ( !$valid->isOK() ) { - wfDebugLog( 'CentralAuthRename', "Invalid page move: {$oldPage->getPrefixedText()} -> {$newPage->getPrefixedText()}" ); + wfDebugLog( 'CentralAuthRename', "Invalid page move: {$oldPage} -> {$newPage}" ); return; } @@ -69,7 +69,7 @@ $status = $mp->move( $this->user, $msg, !$this->params['suppressredirects'] ); if ( !$status->isOK() ) { - wfDebugLog( 'CentralAuthRename', "Page move failed: {$oldPage->getPrefixedText()} -> {$newPage->getPrefixedText()}" ); + wfDebugLog( 'CentralAuthRename', "Page move failed: {$oldPage} -> {$newPage}" ); } } } diff --git a/includes/specials/SpecialCentralAutoLogin.php b/includes/specials/SpecialCentralAutoLogin.php index 46ab01d..4befd4c 100644 --- a/includes/specials/SpecialCentralAutoLogin.php +++ b/includes/specials/SpecialCentralAutoLogin.php @@ -483,7 +483,8 @@ } } if ( !$centralUser->isAttached() ) { - $this->doFinalOutput( false, 'Local user is not attached', self::getInlineScript( 'anon-set.js' ) ); + $this->doFinalOutput( + false, 'Local user is not attached', self::getInlineScript( 'anon-set.js' ) ); ScopedCallback::consume( $delay ); return; } @@ -491,10 +492,13 @@ $this->session->setUser( User::newFromName( $centralUser->getName() ) ); ScopedCallback::consume( $delay ); - \MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autologin success', array( - 'event' => 'autologin', - 'type' => 'success', - ) ); + \MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( + 'Autologin success', + array( + 'event' => 'autologin', + 'type' => 'success', + ) + ); $script = self::getInlineScript( 'anon-remove.js' ); -- To view, visit https://gerrit.wikimedia.org/r/309877 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I769a75512fc523da94377098567b53d23a03cc38 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/extensions/CentralAuth Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits