Merge "rdbms: make runOnTransactionIdleCallbacks() reset DBO_TRX on exceptions"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index 7425bf7..1f92c47 100644 (file)
@@ -3442,16 +3442,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $this->trxIdleCallbacks = []; // consumed (and recursion guard)
                        $this->trxEndCallbacks = []; // consumed (recursion guard)
                        foreach ( $callbacks as $callback ) {
+                               ++$count;
+                               list( $phpCallback ) = $callback;
+                               $this->clearFlag( self::DBO_TRX ); // make each query its own transaction
                                try {
-                                       ++$count;
-                                       list( $phpCallback ) = $callback;
-                                       $this->clearFlag( self::DBO_TRX ); // make each query its own transaction
                                        call_user_func( $phpCallback, $trigger, $this );
-                                       if ( $autoTrx ) {
-                                               $this->setFlag( self::DBO_TRX ); // restore automatic begin()
-                                       } else {
-                                               $this->clearFlag( self::DBO_TRX ); // restore auto-commit
-                                       }
                                } catch ( Exception $ex ) {
                                        call_user_func( $this->errorLogger, $ex );
                                        $e = $e ?: $ex;
@@ -3460,6 +3455,12 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                        if ( $this->trxLevel() ) {
                                                $this->rollback( __METHOD__, self::FLUSHING_INTERNAL );
                                        }
+                               } finally {
+                                       if ( $autoTrx ) {
+                                               $this->setFlag( self::DBO_TRX ); // restore automatic begin()
+                                       } else {
+                                               $this->clearFlag( self::DBO_TRX ); // restore auto-commit
+                                       }
                                }
                        }
                } while ( count( $this->trxIdleCallbacks ) );