Replace use of &$this
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index 0bbbb82..d15d6f1 100644 (file)
@@ -26,6 +26,7 @@
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerInterface;
 use Wikimedia\ScopedCallback;
+use Wikimedia\Rdbms\TransactionProfiler;
 
 /**
  * Relational database abstraction object
@@ -69,8 +70,6 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
        protected $cliMode;
        /** @var string Agent name for query profiling */
        protected $agent;
-       /** @var array[] Map of (section ID => info map) for usage section IDs */
-       protected $usageSectionInfo = [];
 
        /** @var BagOStuff APC cache */
        protected $srvCache;
@@ -920,29 +919,16 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
        }
 
        private function doProfiledQuery( $sql, $commentedSql, $isWrite, $fname ) {
-               // Update usage information for all active usage tracking sections
-               foreach ( $this->usageSectionInfo as $id => &$info ) {
-                       if ( $isWrite ) {
-                               ++$info['writeQueries'];
-                       } else {
-                               ++$info['readQueries'];
-                       }
-                       if ( $info['cacheSetOptions'] === null ) {
-                               $info['cacheSetOptions'] = self::getCacheSetOptions( $this );
-                       }
-               }
-               unset( $info ); // destroy any reference
-
                $isMaster = !is_null( $this->getLBInfo( 'master' ) );
-               // generalizeSQL() will probably cut down the query to reasonable
-               // logging size most of the time. The substr is really just a sanity check.
+               # generalizeSQL() will probably cut down the query to reasonable
+               # logging size most of the time. The substr is really just a sanity check.
                if ( $isMaster ) {
                        $queryProf = 'query-m: ' . substr( self::generalizeSQL( $sql ), 0, 255 );
                } else {
                        $queryProf = 'query: ' . substr( self::generalizeSQL( $sql ), 0, 255 );
                }
 
-               // Include query transaction state
+               # Include query transaction state
                $queryProf .= $this->mTrxShortId ? " [TRX#{$this->mTrxShortId}]" : "";
 
                $startTime = microtime( true );
@@ -1434,9 +1420,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                }
 
                $table = $this->tableName( $table );
-               $old = $this->ignoreErrors( true );
-               $res = $this->query( "SELECT 1 FROM $table LIMIT 1", $fname );
-               $this->ignoreErrors( $old );
+               $ignoreErrors = true;
+               $res = $this->query( "SELECT 1 FROM $table LIMIT 1", $fname, $ignoreErrors );
 
                return (bool)$res;
        }
@@ -2329,7 +2314,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $selectOptions );
 
                if ( is_array( $srcTable ) ) {
-                       $srcTable = implode( ',', array_map( [ &$this, 'tableName' ], $srcTable ) );
+                       $srcTable = implode( ',', array_map( [ $this, 'tableName' ], $srcTable ) );
                } else {
                        $srcTable = $this->tableName( $srcTable );
                }
@@ -2877,23 +2862,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                return $this->mTrxLevel && ( $this->mTrxAtomicLevels || !$this->mTrxAutomatic );
        }
 
-       /**
-        * Creates a new table with structure copied from existing table
-        * Note that unlike most database abstraction functions, this function does not
-        * automatically append database prefix, because it works at a lower
-        * abstraction level.
-        * The table names passed to this function shall not be quoted (this
-        * function calls addIdentifierQuotes when needed).
-        *
-        * @param string $oldName Name of table whose structure should be copied
-        * @param string $newName Name of table to be created
-        * @param bool $temporary Whether the new table should be temporary
-        * @param string $fname Calling function name
-        * @throws RuntimeException
-        * @return bool True if operation was successful
-        */
-       public function duplicateTableStructure( $oldName, $newName, $temporary = false,
-               $fname = __METHOD__
+       public function duplicateTableStructure(
+               $oldName, $newName, $temporary = false, $fname = __METHOD__
        ) {
                throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
        }
@@ -3038,33 +3008,20 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
         * @since 1.27
         */
        public static function getCacheSetOptions( IDatabase $db1 ) {
-               $opts = [ 'lag' => 0, 'since' => INF, 'pending' => false ];
+               $res = [ 'lag' => 0, 'since' => INF, 'pending' => false ];
                foreach ( func_get_args() as $db ) {
                        /** @var IDatabase $db */
-                       $dbOpts = $db->getSessionLagStatus();
-                       $dbOpts['pending'] = $db->writesPending();
-                       $opts = self::mergeCacheSetOptions( $opts, $dbOpts );
-               }
-
-               return $opts;
-       }
-
-       /**
-        * @param array $base Map in the format of getCacheSetOptions() results
-        * @param array $other Map in the format of getCacheSetOptions() results
-        * @return array Pessimistically merged result of $base/$other in the format of $base
-        * @since 1.28
-        */
-       public static function mergeCacheSetOptions( array $base, array $other ) {
-               if ( $other['lag'] === false ) {
-                       $base['lag'] = false;
-               } elseif ( $base['lag'] !== false ) {
-                       $base['lag'] = max( $base['lag'], $other['lag'] );
+                       $status = $db->getSessionLagStatus();
+                       if ( $status['lag'] === false ) {
+                               $res['lag'] = false;
+                       } elseif ( $res['lag'] !== false ) {
+                               $res['lag'] = max( $res['lag'], $status['lag'] );
+                       }
+                       $res['since'] = min( $res['since'], $status['since'] );
+                       $res['pending'] = $res['pending'] ?: $db->writesPending();
                }
-               $base['since'] = min( $base['since'], $other['since'] );
-               $base['pending'] = $base['pending'] ?: $other['pending'];
 
-               return $base;
+               return $res;
        }
 
        public function getLag() {
@@ -3411,25 +3368,6 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                $this->tableAliases = $aliases;
        }
 
-       public function declareUsageSectionStart( $id ) {
-               $this->usageSectionInfo[$id] = [
-                       'readQueries' => 0,
-                       'writeQueries' => 0,
-                       'cacheSetOptions' => null
-               ];
-       }
-
-       public function declareUsageSectionEnd( $id ) {
-               if ( !isset( $this->usageSectionInfo[$id] ) ) {
-                       throw new InvalidArgumentException( "No section with ID '$id'" );
-               }
-
-               $info = $this->usageSectionInfo[$id];
-               unset( $this->usageSectionInfo[$id] );
-
-               return $info;
-       }
-
        /**
         * @return bool Whether a DB user is required to access the DB
         * @since 1.28