From: Aaron Schulz Date: Sun, 11 Sep 2016 19:52:11 +0000 (-0700) Subject: Make SessionBackend::save() update the user post-send X-Git-Tag: 1.31.0-rc.0~5134^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=4a2085523fce81ba4d75eb6946f5c7ae069bb1d2;p=lhc%2Fweb%2Fwiklou.git Make SessionBackend::save() update the user post-send Bug: T92357 Change-Id: Id4f4991aca1ceeb74b59e980f09863041246a4fc --- diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 8cf009f47a..218337a95a 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -899,6 +899,7 @@ class MediaWiki { // Do any deferred jobs DeferredUpdates::doUpdates( 'enqueue' ); + DeferredUpdates::setImmediateMode( true ); // Make sure any lazy jobs are pushed JobQueueGroup::pushLazyJobs(); diff --git a/includes/deferred/DeferredUpdates.php b/includes/deferred/DeferredUpdates.php index 8a761f516f..1ba6c1febd 100644 --- a/includes/deferred/DeferredUpdates.php +++ b/includes/deferred/DeferredUpdates.php @@ -52,6 +52,8 @@ class DeferredUpdates { private static $preSendUpdates = []; /** @var DeferrableUpdate[] Updates to be deferred until after request end */ private static $postSendUpdates = []; + /** @var bool Whether to just run updates in addUpdate() */ + private static $immediateMode = false; const ALL = 0; // all updates; in web requests, use only after flushing the output buffer const PRESEND = 1; // for updates that should run before flushing output buffer @@ -85,6 +87,12 @@ class DeferredUpdates { self::push( self::$postSendUpdates, $update ); } + if ( self::$immediateMode ) { + // No more explicit doUpdates() calls will happen, so run this now + self::doUpdates( 'run' ); + return; + } + // Try to run the updates now if in CLI mode and no transaction is active. // This covers scripts that don't/barely use the DB but make updates to other stores. if ( $wgCommandLineMode ) { @@ -126,6 +134,14 @@ class DeferredUpdates { } } + /** + * @param bool $value Whether to just immediately run updates in addUpdate() + * @since 1.28 + */ + public static function setImmediateMode( $value ) { + self::$immediateMode = (bool)$value; + } + /** * @param DeferrableUpdate[] $queue * @param DeferrableUpdate $update diff --git a/includes/session/SessionBackend.php b/includes/session/SessionBackend.php index 263cb11f54..ea811b6563 100644 --- a/includes/session/SessionBackend.php +++ b/includes/session/SessionBackend.php @@ -642,7 +642,11 @@ final class SessionBackend { ] ); $this->user->setToken(); if ( !wfReadOnly() ) { - $this->user->saveSettings(); + // Promise that the token set here will be valid; save it at end of request + $user = $this->user; + \DeferredUpdates::addCallableUpdate( function () use ( $user ) { + $user->saveSettings(); + } ); } $this->metaDirty = true; }