Merge "Remove setting of $wgReadOnly in LBFactoryMulti"
[lhc/web/wiklou.git] / includes / db / Database.php
index 4bbb491..ebcf540 100644 (file)
@@ -124,9 +124,9 @@ abstract class DatabaseBase implements IDatabase {
        /**
         * Array of levels of atomicity within transactions
         *
-        * @var SplStack
+        * @var array
         */
-       private $mTrxAtomicLevels;
+       private $mTrxAtomicLevels = array();
 
        /**
         * Record if the current transaction was started implicitly by DatabaseBase::startAtomic
@@ -479,11 +479,7 @@ abstract class DatabaseBase implements IDatabase {
         *   - DBO_PERSISTENT: use persistant database connection
         */
        public function setFlag( $flag ) {
-               global $wgDebugDBTransactions;
                $this->mFlags |= $flag;
-               if ( ( $flag & DBO_TRX ) && $wgDebugDBTransactions ) {
-                       wfDebug( "Implicit transactions are now enabled.\n" );
-               }
        }
 
        /**
@@ -498,11 +494,7 @@ abstract class DatabaseBase implements IDatabase {
         *   - DBO_PERSISTENT: use persistant database connection
         */
        public function clearFlag( $flag ) {
-               global $wgDebugDBTransactions;
                $this->mFlags &= ~$flag;
-               if ( ( $flag & DBO_TRX ) && $wgDebugDBTransactions ) {
-                       wfDebug( "Implicit transactions are now disabled.\n" );
-               }
        }
 
        /**
@@ -607,9 +599,7 @@ abstract class DatabaseBase implements IDatabase {
         * @param array $params Parameters passed from DatabaseBase::factory()
         */
        function __construct( array $params ) {
-               global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode, $wgDebugDBTransactions;
-
-               $this->mTrxAtomicLevels = new SplStack;
+               global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode;
 
                $server = $params['host'];
                $user = $params['user'];
@@ -624,14 +614,8 @@ abstract class DatabaseBase implements IDatabase {
                if ( $this->mFlags & DBO_DEFAULT ) {
                        if ( $wgCommandLineMode ) {
                                $this->mFlags &= ~DBO_TRX;
-                               if ( $wgDebugDBTransactions ) {
-                                       wfDebug( "Implicit transaction open disabled.\n" );
-                               }
                        } else {
                                $this->mFlags |= DBO_TRX;
-                               if ( $wgDebugDBTransactions ) {
-                                       wfDebug( "Implicit transaction open enabled.\n" );
-                               }
                        }
                }
 
@@ -928,7 +912,7 @@ abstract class DatabaseBase implements IDatabase {
         *     for a successful read query, or false on failure if $tempIgnore set
         */
        public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
-               global $wgUser, $wgDebugDBTransactions, $wgDebugDumpSqlLength;
+               global $wgUser;
 
                $this->mLastQuery = $sql;
 
@@ -958,9 +942,6 @@ abstract class DatabaseBase implements IDatabase {
                $commentedSql = preg_replace( '/\s|$/', " /* $fname $userName */ ", $sql, 1 );
 
                if ( !$this->mTrxLevel && $this->getFlag( DBO_TRX ) && $this->isTransactableQuery( $sql ) ) {
-                       if ( $wgDebugDBTransactions ) {
-                               wfDebug( "Implicit transaction start.\n" );
-                       }
                        $this->begin( __METHOD__ . " ($fname)" );
                        $this->mTrxAutomatic = true;
                }
@@ -992,15 +973,7 @@ abstract class DatabaseBase implements IDatabase {
                }
 
                if ( $this->debug() ) {
-                       static $cnt = 0;
-
-                       $cnt++;
-                       $sqlx = $wgDebugDumpSqlLength ? substr( $commentedSql, 0, $wgDebugDumpSqlLength )
-                               : $commentedSql;
-                       $sqlx = strtr( $sqlx, "\t\n", '  ' );
-
-                       $master = $isMaster ? 'master' : 'slave';
-                       wfDebug( "Query {$this->mDBname} ($cnt) ($master): $sqlx\n" );
+                       wfDebugLog( 'queries', sprintf( "%s: %s", $this->mDBname, $sql ) );
                }
 
                $queryId = MWDebug::query( $sql, $fname, $isMaster );
@@ -1756,7 +1729,7 @@ abstract class DatabaseBase implements IDatabase {
         *
         * @return string
         */
-       static function generalizeSQL( $sql ) {
+       protected static function generalizeSQL( $sql ) {
                # This does the same as the regexp below would do, but in such a way
                # as to avoid crashing php on some large strings.
                # $sql = preg_replace( "/'([^\\\\']|\\\\.)*'|\"([^\\\\\"]|\\\\.)*\"/", "'X'", $sql );
@@ -3395,7 +3368,7 @@ abstract class DatabaseBase implements IDatabase {
                        }
                }
 
-               $this->mTrxAtomicLevels->push( $fname );
+               $this->mTrxAtomicLevels[] = $fname;
        }
 
        /**
@@ -3413,13 +3386,13 @@ abstract class DatabaseBase implements IDatabase {
                if ( !$this->mTrxLevel ) {
                        throw new DBUnexpectedError( $this, 'No atomic transaction is open.' );
                }
-               if ( $this->mTrxAtomicLevels->isEmpty() ||
-                       $this->mTrxAtomicLevels->pop() !== $fname
+               if ( !$this->mTrxAtomicLevels ||
+                       array_pop( $this->mTrxAtomicLevels ) !== $fname
                ) {
                        throw new DBUnexpectedError( $this, 'Invalid atomic section ended.' );
                }
 
-               if ( $this->mTrxAtomicLevels->isEmpty() && $this->mTrxAutomaticAtomic ) {
+               if ( !$this->mTrxAtomicLevels && $this->mTrxAutomaticAtomic ) {
                        $this->commit( $fname, 'flush' );
                }
        }
@@ -3440,10 +3413,8 @@ abstract class DatabaseBase implements IDatabase {
         * @throws DBError
         */
        final public function begin( $fname = __METHOD__ ) {
-               global $wgDebugDBTransactions;
-
                if ( $this->mTrxLevel ) { // implicit commit
-                       if ( !$this->mTrxAtomicLevels->isEmpty() ) {
+                       if ( $this->mTrxAtomicLevels ) {
                                // If the current transaction was an automatic atomic one, then we definitely have
                                // a problem. Same if there is any unclosed atomic level.
                                throw new DBUnexpectedError( $this,
@@ -3462,9 +3433,8 @@ abstract class DatabaseBase implements IDatabase {
                                        ) )
                                );
                        } else {
-                               // if the transaction was automatic and has done write operations,
-                               // log it if $wgDebugDBTransactions is enabled.
-                               if ( $this->mTrxDoneWrites && $wgDebugDBTransactions ) {
+                               // if the transaction was automatic and has done write operations
+                               if ( $this->mTrxDoneWrites ) {
                                        wfDebug( "$fname: Automatic transaction with writes in progress" .
                                                " (from {$this->mTrxFname}), performing implicit commit!\n"
                                        );
@@ -3491,7 +3461,7 @@ abstract class DatabaseBase implements IDatabase {
                $this->mTrxDoneWrites = false;
                $this->mTrxAutomatic = false;
                $this->mTrxAutomaticAtomic = false;
-               $this->mTrxAtomicLevels = new SplStack;
+               $this->mTrxAtomicLevels = array();
                $this->mTrxIdleCallbacks = array();
                $this->mTrxPreCommitCallbacks = array();
                $this->mTrxShortId = wfRandomString( 12 );
@@ -3524,7 +3494,7 @@ abstract class DatabaseBase implements IDatabase {
         * @throws DBUnexpectedError
         */
        final public function commit( $fname = __METHOD__, $flush = '' ) {
-               if ( !$this->mTrxAtomicLevels->isEmpty() ) {
+               if ( $this->mTrxLevel && $this->mTrxAtomicLevels ) {
                        // There are still atomic sections open. This cannot be ignored
                        throw new DBUnexpectedError(
                                $this,
@@ -3610,7 +3580,7 @@ abstract class DatabaseBase implements IDatabase {
                $this->doRollback( $fname );
                $this->mTrxIdleCallbacks = array(); // cancel
                $this->mTrxPreCommitCallbacks = array(); // cancel
-               $this->mTrxAtomicLevels = new SplStack;
+               $this->mTrxAtomicLevels = array();
                if ( $this->mTrxDoneWrites ) {
                        $this->getTransactionProfiler()->transactionWritingOut(
                                $this->mServer, $this->mDBname, $this->mTrxShortId );
@@ -4248,3 +4218,8 @@ abstract class DatabaseBase implements IDatabase {
                }
        }
 }
+
+abstract class Database extends DatabaseBase {
+       // B/C until nothing type hints for DatabaseBase
+       // @TODO: finish renaming DatabaseBase => Database
+}