list( $phpCallback ) = $callback;
$this->clearFlag( DBO_TRX ); // make each query its own transaction
call_user_func( $phpCallback );
- $this->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
+ if ( $autoTrx ) {
+ $this->setFlag( DBO_TRX ); // restore automatic begin()
+ } else {
+ $this->clearFlag( DBO_TRX ); // restore auto-commit
+ }
} catch ( Exception $e ) {
if ( $ePrior ) {
MWExceptionHandler::logException( $ePrior );
$this->assertFalse( $this->db->tableExists( 'foobarbaz' ) );
$this->assertInternalType( 'int', $res->numRows() );
}
+
+ public function testTransactionIdle() {
+ $db = $this->db;
+
+ $db->setFlag( DBO_TRX );
+ $flagSet = null;
+ $db->onTransactionIdle( function() use ( $db, &$flagSet ) {
+ $flagSet = $db->getFlag( DBO_TRX );
+ } );
+ $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
+ $this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
+
+ $db->clearFlag( DBO_TRX );
+ $flagSet = null;
+ $db->onTransactionIdle( function() use ( $db, &$flagSet ) {
+ $flagSet = $db->getFlag( DBO_TRX );
+ } );
+ $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
+ $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
+
+ $db->clearFlag( DBO_TRX );
+ $db->onTransactionIdle( function() use ( $db ) {
+ $db->setFlag( DBO_TRX );
+ } );
+ $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
+ }
}