Make TransactionProfiler::setSilenced() calls handle nesting
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 13 Oct 2016 01:14:03 +0000 (18:14 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 13 Oct 2016 01:14:03 +0000 (18:14 -0700)
Change-Id: I6511a72a0fb921468a8a19ceb4d0a8ae669aa6e4

includes/auth/AuthManager.php
includes/libs/rdbms/TransactionProfiler.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
includes/specials/SpecialConfirmemail.php
includes/specials/SpecialEmailInvalidate.php

index e223e16..eeb233e 100644 (file)
@@ -1678,7 +1678,7 @@ class AuthManager implements LoggerAwareInterface {
 
                // Ignore warnings about master connections/writes...hard to avoid here
                $trxProfiler = \Profiler::instance()->getTransactionProfiler();
-               $trxProfiler->setSilenced( true );
+               $old = $trxProfiler->setSilenced( true );
                try {
                        $status = $user->addToDatabase();
                        if ( !$status->isOK() ) {
@@ -1704,7 +1704,7 @@ class AuthManager implements LoggerAwareInterface {
                                return $status;
                        }
                } catch ( \Exception $ex ) {
-                       $trxProfiler->setSilenced( false );
+                       $trxProfiler->setSilenced( $old );
                        $this->logger->error( __METHOD__ . ': {username} failed with exception {exception}', [
                                'username' => $username,
                                'exception' => $ex,
@@ -1743,7 +1743,7 @@ class AuthManager implements LoggerAwareInterface {
                        $logEntry->insert();
                }
 
-               $trxProfiler->setSilenced( false );
+               $trxProfiler->setSilenced( $old );
 
                if ( $login ) {
                        $this->setSessionDataForUser( $user );
index 12f6df5..bf5e299 100644 (file)
@@ -80,11 +80,15 @@ class TransactionProfiler implements LoggerAwareInterface {
        }
 
        /**
-        * @param bool $value
+        * @param bool $value New value
+        * @return bool Old value
         * @since 1.28
         */
        public function setSilenced( $value ) {
+               $old = $this->silenced;
                $this->silenced = $value;
+
+               return $old;
        }
 
        /**
index 083dcd6..32df19d 100644 (file)
@@ -1324,7 +1324,7 @@ class LoadBalancer implements ILoadBalancer {
                        $cache->makeGlobalKey( __CLASS__, 'server-read-only', $masterServer ),
                        self::TTL_CACHE_READONLY,
                        function () use ( $domain, $conn ) {
-                               $this->trxProfiler->setSilenced( true );
+                               $old = $this->trxProfiler->setSilenced( true );
                                try {
                                        $dbw = $conn ?: $this->getConnection( self::DB_MASTER, [], $domain );
                                        $readOnly = (int)$dbw->serverIsReadOnly();
@@ -1334,7 +1334,7 @@ class LoadBalancer implements ILoadBalancer {
                                } catch ( DBError $e ) {
                                        $readOnly = 0;
                                }
-                               $this->trxProfiler->setSilenced( false );
+                               $this->trxProfiler->setSilenced( $old );
                                return $readOnly;
                        },
                        [ 'pcTTL' => $cache::TTL_PROC_LONG, 'busyValue' => 0 ]
index 7b4e9db..f494b9d 100644 (file)
@@ -69,9 +69,9 @@ class EmailConfirmation extends UnlistedSpecialPage {
                                $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
                        }
                } else {
-                       $trxProfiler->setSilenced( true );
+                       $old = $trxProfiler->setSilenced( true );
                        $this->attemptConfirm( $code );
-                       $trxProfiler->setSilenced( false );
+                       $trxProfiler->setSilenced( $old );
                }
        }
 
index d2e3e7f..c54abad 100644 (file)
@@ -45,9 +45,9 @@ class EmailInvalidation extends UnlistedSpecialPage {
                $this->checkReadOnly();
                $this->checkPermissions();
 
-               $trxProfiler->setSilenced( true );
+               $old = $trxProfiler->setSilenced( true );
                $this->attemptInvalidate( $code );
-               $trxProfiler->setSilenced( false );
+               $trxProfiler->setSilenced( $old );
        }
 
        /**