From: Aaron Schulz Date: Fri, 25 May 2018 23:02:27 +0000 (-0700) Subject: rdbms: make runOnTransactionIdleCallbacks() reset DBO_TRX on exceptions X-Git-Tag: 1.34.0-rc.0~5242^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22brouteur%22%2C%28%24id_rubrique%20?a=commitdiff_plain;h=8880a25112eaf7652d907d17d17607a5c6ceb26b;p=lhc%2Fweb%2Fwiklou.git rdbms: make runOnTransactionIdleCallbacks() reset DBO_TRX on exceptions Change-Id: Ibbb2a3ebf9dd970772ee704aa643a3843f20a3b5 --- diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index aeda5b9ce0..efef121cf0 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -3448,16 +3448,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; @@ -3466,6 +3461,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 ) ); diff --git a/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php b/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php index 3f0dae633f..c12882b818 100644 --- a/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php @@ -260,6 +260,16 @@ class DatabaseTest extends PHPUnit\Framework\TestCase { $lbFactory->commitMasterChanges( __METHOD__ ); $this->assertFalse( $called, 'Not called in next round commit' ); + + $db->setFlag( DBO_TRX ); + try { + $db->onTransactionCommitOrIdle( function () { + throw new RuntimeException( 'test' ); + } ); + $this->fail( "Exception not thrown" ); + } catch ( RuntimeException $e ) { + $this->assertTrue( $db->getFlag( DBO_TRX ) ); + } } /**