Add missing IDatabase type hints to all doAtomicSection() calls
[lhc/web/wiklou.git] / includes / user / User.php
index 5b07315..6608d99 100644 (file)
@@ -46,18 +46,20 @@ use Wikimedia\Rdbms\IDatabase;
  * of the database.
  */
 class User implements IDBAccessObject, UserIdentity {
+
        /**
-        * @const int Number of characters in user_token field.
+        * Number of characters required for the user_token field.
         */
        const TOKEN_LENGTH = 32;
 
        /**
-        * @const string An invalid value for user_token
+        * An invalid string value for the user_token field.
         */
        const INVALID_TOKEN = '*** INVALID ***';
 
        /**
-        * @const int Serialized record version.
+        * Version number to tag cached versions of serialized User objects. Should be increased when
+        * {@link $mCacheVars} or one of it's members changes.
         */
        const VERSION = 13;
 
@@ -1288,17 +1290,6 @@ class User implements IDBAccessObject, UserIdentity {
                return $name;
        }
 
-       /**
-        * Return a random password.
-        *
-        * @deprecated since 1.27, use PasswordFactory::generateRandomPasswordString()
-        * @return string New random password
-        */
-       public static function randomPassword() {
-               global $wgMinimalPasswordLength;
-               return PasswordFactory::generateRandomPasswordString( $wgMinimalPasswordLength );
-       }
-
        /**
         * Set cached properties to default.
         *
@@ -1715,7 +1706,7 @@ class User implements IDBAccessObject, UserIdentity {
 
                if ( $success ) {
                        $this->mTouched = $newTouched;
-                       $this->clearSharedCache();
+                       $this->clearSharedCache( 'changed' );
                } else {
                        // Clears on failure too since that is desired if the cache is stale
                        $this->clearSharedCache( 'refresh' );
@@ -2771,29 +2762,26 @@ class User implements IDBAccessObject, UserIdentity {
         *
         * Called implicitly from invalidateCache() and saveSettings().
         *
-        * @param string $mode Use 'refresh' to clear now; otherwise before DB commit
+        * @param string $mode Use 'refresh' to clear now or 'changed' to clear before DB commit
         */
-       public function clearSharedCache( $mode = 'changed' ) {
+       public function clearSharedCache( $mode = 'refresh' ) {
                if ( !$this->getId() ) {
                        return;
                }
 
+               $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $key = $this->getCacheKey( $cache );
+
                if ( $mode === 'refresh' ) {
-                       $cache->delete( $key, 1 );
+                       $cache->delete( $key, 1 ); // low tombstone/"hold-off" TTL
                } else {
-                       $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
-                       if ( $lb->hasOrMadeRecentMasterChanges() ) {
-                               $lb->getConnection( DB_MASTER )->onTransactionPreCommitOrIdle(
-                                       function () use ( $cache, $key ) {
-                                               $cache->delete( $key );
-                                       },
-                                       __METHOD__
-                               );
-                       } else {
-                               $cache->delete( $key );
-                       }
+                       $lb->getConnection( DB_MASTER )->onTransactionPreCommitOrIdle(
+                               function () use ( $cache, $key ) {
+                                       $cache->delete( $key );
+                               },
+                               __METHOD__
+                       );
                }
        }
 
@@ -2804,7 +2792,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public function invalidateCache() {
                $this->touch();
-               $this->clearSharedCache();
+               $this->clearSharedCache( 'changed' );
        }
 
        /**
@@ -4209,7 +4197,7 @@ class User implements IDBAccessObject, UserIdentity {
                $newTouched = $this->newTouchedTimestamp();
 
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $newTouched ) {
+               $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) use ( $newTouched ) {
                        global $wgActorTableSchemaMigrationStage;
 
                        $dbw->update( 'user',
@@ -4255,7 +4243,7 @@ class User implements IDBAccessObject, UserIdentity {
                $this->saveOptions();
 
                Hooks::run( 'UserSaveSettings', [ $this ] );
-               $this->clearSharedCache();
+               $this->clearSharedCache( 'changed' );
                $this->getUserPage()->purgeSquid();
        }
 
@@ -4335,7 +4323,7 @@ class User implements IDBAccessObject, UserIdentity {
                        $fields["user_$name"] = $value;
                }
 
-               return $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $fields ) {
+               return $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) use ( $fields ) {
                        $dbw->insert( 'user', $fields, $fname, [ 'IGNORE' ] );
                        if ( $dbw->affectedRows() ) {
                                $newUser = self::newFromId( $dbw->insertId() );
@@ -4389,7 +4377,7 @@ class User implements IDBAccessObject, UserIdentity {
                $this->mTouched = $this->newTouchedTimestamp();
 
                $dbw = wfGetDB( DB_MASTER );
-               $status = $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) {
+               $status = $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) {
                        $noPass = PasswordFactory::newInvalidPassword()->toString();
                        $dbw->insert( 'user',
                                [