Merge "RCFilters: define consistent interface in ChangesListFilterGroup"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index e7417eb..c04e167 100644 (file)
@@ -1138,6 +1138,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
         *
         * @param string $error Error text
         * @param int $errno Error number
+        * @return bool
         */
        protected function wasQueryTimeout( $error, $errno ) {
                return false;
@@ -2014,11 +2015,21 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                // No alias? Set it equal to the table name
                                $alias = $table;
                        }
+
+                       if ( is_array( $table ) ) {
+                               // A parenthesized group
+                               $joinedTable = '('
+                                       . $this->tableNamesWithIndexClauseOrJOIN( $table, $use_index, $ignore_index, $join_conds )
+                                       . ')';
+                       } else {
+                               $joinedTable = $this->tableNameWithAlias( $table, $alias );
+                       }
+
                        // Is there a JOIN clause for this table?
                        if ( isset( $join_conds[$alias] ) ) {
                                list( $joinType, $conds ) = $join_conds[$alias];
                                $tableClause = $joinType;
-                               $tableClause .= ' ' . $this->tableNameWithAlias( $table, $alias );
+                               $tableClause .= ' ' . $joinedTable;
                                if ( isset( $use_index[$alias] ) ) { // has USE INDEX?
                                        $use = $this->useIndexClause( implode( ',', (array)$use_index[$alias] ) );
                                        if ( $use != '' ) {
@@ -2040,7 +2051,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                $retJOIN[] = $tableClause;
                        } elseif ( isset( $use_index[$alias] ) ) {
                                // Is there an INDEX clause for this table?
-                               $tableClause = $this->tableNameWithAlias( $table, $alias );
+                               $tableClause = $joinedTable;
                                $tableClause .= ' ' . $this->useIndexClause(
                                                implode( ',', (array)$use_index[$alias] )
                                        );
@@ -2048,14 +2059,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                $ret[] = $tableClause;
                        } elseif ( isset( $ignore_index[$alias] ) ) {
                                // Is there an INDEX clause for this table?
-                               $tableClause = $this->tableNameWithAlias( $table, $alias );
+                               $tableClause = $joinedTable;
                                $tableClause .= ' ' . $this->ignoreIndexClause(
                                                implode( ',', (array)$ignore_index[$alias] )
                                        );
 
                                $ret[] = $tableClause;
                        } else {
-                               $tableClause = $this->tableNameWithAlias( $table, $alias );
+                               $tableClause = $joinedTable;
 
                                $ret[] = $tableClause;
                        }
@@ -2407,6 +2418,37 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        );
                }
 
+               return $this->nonNativeInsertSelect(
+                       $destTable,
+                       $srcTable,
+                       $varMap,
+                       $conds,
+                       $fname,
+                       $insertOptions,
+                       $selectOptions,
+                       $selectJoinConds
+               );
+       }
+
+       /**
+        * Implementation of insertSelect() based on select() and insert()
+        *
+        * @see IDatabase::insertSelect()
+        * @since 1.30
+        * @param string $destTable
+        * @param string|array $srcTable
+        * @param array $varMap
+        * @param array $conds
+        * @param string $fname
+        * @param array $insertOptions
+        * @param array $selectOptions
+        * @param array $selectJoinConds
+        * @return bool
+        */
+       protected function nonNativeInsertSelect( $destTable, $srcTable, $varMap, $conds,
+               $fname = __METHOD__,
+               $insertOptions = [], $selectOptions = [], $selectJoinConds = []
+       ) {
                // For web requests, do a locking SELECT and then INSERT. This puts the SELECT burden
                // on only the master (without needing row-based-replication). It also makes it easy to
                // know how big the INSERT is going to be.
@@ -3046,8 +3088,16 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
 
                $this->mTrxIdleCallbacks = []; // clear
                $this->mTrxPreCommitCallbacks = []; // clear
-               $this->runOnTransactionIdleCallbacks( self::TRIGGER_ROLLBACK );
-               $this->runTransactionListenerCallbacks( self::TRIGGER_ROLLBACK );
+               try {
+                       $this->runOnTransactionIdleCallbacks( self::TRIGGER_ROLLBACK );
+               } catch ( Exception $e ) {
+                       // already logged; finish and let LoadBalancer move on during mass-rollback
+               }
+               try {
+                       $this->runTransactionListenerCallbacks( self::TRIGGER_ROLLBACK );
+               } catch ( Exception $e ) {
+                       // already logged; let LoadBalancer move on during mass-rollback
+               }
        }
 
        /**