From 9a8c8ab98c28ad17e5d4b3f1f7ef52b4f9745eaa Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 12 Oct 2016 18:14:03 -0700 Subject: [PATCH] Make TransactionProfiler::setSilenced() calls handle nesting Change-Id: I6511a72a0fb921468a8a19ceb4d0a8ae669aa6e4 --- includes/auth/AuthManager.php | 6 +++--- includes/libs/rdbms/TransactionProfiler.php | 6 +++++- includes/libs/rdbms/loadbalancer/LoadBalancer.php | 4 ++-- includes/specials/SpecialConfirmemail.php | 4 ++-- includes/specials/SpecialEmailInvalidate.php | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index e223e16e69..eeb233e465 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -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 ); diff --git a/includes/libs/rdbms/TransactionProfiler.php b/includes/libs/rdbms/TransactionProfiler.php index 12f6df5d4a..bf5e299865 100644 --- a/includes/libs/rdbms/TransactionProfiler.php +++ b/includes/libs/rdbms/TransactionProfiler.php @@ -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; } /** diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 083dcd68cd..32df19dcd7 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -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 ] diff --git a/includes/specials/SpecialConfirmemail.php b/includes/specials/SpecialConfirmemail.php index 7b4e9db01e..f494b9d666 100644 --- a/includes/specials/SpecialConfirmemail.php +++ b/includes/specials/SpecialConfirmemail.php @@ -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 ); } } diff --git a/includes/specials/SpecialEmailInvalidate.php b/includes/specials/SpecialEmailInvalidate.php index d2e3e7f132..c54abadd54 100644 --- a/includes/specials/SpecialEmailInvalidate.php +++ b/includes/specials/SpecialEmailInvalidate.php @@ -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 ); } /** -- 2.20.1