From: Aaron Schulz Date: Fri, 26 Aug 2016 05:20:23 +0000 (-0700) Subject: Make database ping() method avoid starting transactions X-Git-Tag: 1.31.0-rc.0~5870^2 X-Git-Url: https://git.cyclocoop.org/%2C?a=commitdiff_plain;h=ce57a03aec280b7187ad5e15c0158151638575d6;p=lhc%2Fweb%2Fwiklou.git Make database ping() method avoid starting transactions Also use the $ignoreErrors flag to simplify the code. Change-Id: Ieb685366b35487abcd618eb73cf67f4c266a70c7 --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 59c1207e49..e07836b225 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2972,13 +2972,14 @@ abstract class DatabaseBase implements IDatabase { if ( $this->isOpen() && ( microtime( true ) - $this->lastPing ) < self::PING_TTL ) { return true; } - try { - // This will reconnect if possible, or error out if not - $this->query( "SELECT 1 AS ping", __METHOD__ ); - return true; - } catch ( DBError $e ) { - return false; - } + + $ignoreErrors = true; + $this->clearFlag( DBO_TRX, self::REMEMBER_PRIOR ); + // This will reconnect if possible or return false if not + $ok = (bool)$this->query( "SELECT 1 AS ping", __METHOD__, $ignoreErrors ); + $this->restoreFlags( self::RESTORE_PRIOR ); + + return $ok; } /**