Merge "Avoid "Transaction already in progress" errors in SiteStatsUpdate::doUpdate"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 15 Aug 2013 17:56:35 +0000 (17:56 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 15 Aug 2013 17:56:35 +0000 (17:56 +0000)
1  2 
includes/db/Database.php

diff --combined includes/db/Database.php
@@@ -242,7 -242,6 +242,7 @@@ abstract class DatabaseBase implements 
  
        protected $mTablePrefix;
        protected $mFlags;
 +      protected $mForeign;
        protected $mTrxLevel = 0;
        protected $mErrorCount = 0;
        protected $mLBInfo = array();
         * @param string $dbName database name
         * @param $flags
         * @param string $tablePrefix database table prefixes. By default use the prefix gave in LocalSettings.php
 +       * @param bool $foreign disable some operations specific to local databases
         */
        function __construct( $server = false, $user = false, $password = false, $dbName = false,
 -              $flags = 0, $tablePrefix = 'get from global'
 +              $flags = 0, $tablePrefix = 'get from global', $foreign = false
        ) {
                global $wgDBprefix, $wgCommandLineMode, $wgDebugDBTransactions;
  
                        $this->mTablePrefix = $tablePrefix;
                }
  
 +              $this->mForeign = $foreign;
 +
                if ( $user ) {
                        $this->open( $server, $user, $password, $dbName );
                }
                                isset( $p['password'] ) ? $p['password'] : false,
                                isset( $p['dbname'] ) ? $p['dbname'] : false,
                                isset( $p['flags'] ) ? $p['flags'] : 0,
 -                              isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global'
 +                              isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global',
 +                              isset( $p['foreign'] ) ? $p['foreign'] : false
                        );
                } else {
                        return null;
                } else {
                        list( $table ) = $dbDetails;
                        if ( $wgSharedDB !== null # We have a shared database
 +                              && $this->mForeign == false # We're not working on a foreign database
                                && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`'
                                && in_array( $table, $wgSharedTables ) # A shared table is selected
                        ) {
                        foreach ( $callbacks as $callback ) {
                                try {
                                        $this->clearFlag( DBO_TRX ); // make each query its own transaction
-                                       $callback();
+                                       call_user_func( $callback );
                                        $this->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
-                               } catch ( Exception $e ) {
-                               }
+                               } catch ( Exception $e ) {}
                        }
                } while ( count( $this->mTrxIdleCallbacks ) );
  
                        $this->mTrxPreCommitCallbacks = array(); // recursion guard
                        foreach ( $callbacks as $callback ) {
                                try {
-                                       $callback();
+                                       call_user_func( $callback );
                                } catch ( Exception $e ) {}
                        }
                } while ( count( $this->mTrxPreCommitCallbacks ) );