Make database ping() method avoid starting transactions
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 26 Aug 2016 05:20:23 +0000 (22:20 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 26 Aug 2016 19:48:39 +0000 (19:48 +0000)
Also use the $ignoreErrors flag to simplify the code.

Change-Id: Ieb685366b35487abcd618eb73cf67f4c266a70c7

includes/db/Database.php

index 59c1207..e07836b 100644 (file)
@@ -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;
        }
 
        /**