$logEntry->setTags( $tags );
$logid = $logEntry->insert();
$dbw->onTransactionPreCommitOrIdle(
- function () use ( $dbw, $logEntry, $logid ) {
+ function () use ( $logEntry, $logid ) {
$logEntry->publish( $logid );
},
__METHOD__
// errors that bubble up will rollback the main commit round.
$fname = __METHOD__;
$dbw->onTransactionPreCommitOrIdle(
- function () use ( $dbw, $jobs, $flags, $fname ) {
+ function ( IDatabase $dbw ) use ( $jobs, $flags, $fname ) {
$this->doBatchPushInternal( $dbw, $jobs, $flags, $fname );
},
$fname
$dbw = $this->getMasterDB();
$cache = $this->dupCache;
$dbw->onTransactionIdle(
- function () use ( $cache, $params, $key, $dbw ) {
+ function () use ( $cache, $params, $key ) {
$timestamp = $cache->get( $key ); // current last timestamp of this job
if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
return true; // a newer version of this root job was enqueued
// No transaction is active nor will start implicitly, so make one for this callback
$this->startAtomic( __METHOD__, self::ATOMIC_CANCELABLE );
try {
- call_user_func( $callback );
+ call_user_func( $callback, $this );
$this->endAtomic( __METHOD__ );
} catch ( Exception $e ) {
$this->cancelAtomic( __METHOD__ );
if ( in_array( $entry[2], $sectionIds, true ) ) {
$callback = $entry[0];
$this->trxEndCallbacks[$key][0] = function () use ( $callback ) {
- return $callback( self::TRIGGER_ROLLBACK );
+ return $callback( self::TRIGGER_ROLLBACK, $this );
};
}
}
try {
list( $phpCallback ) = $callback;
$this->clearFlag( self::DBO_TRX ); // make each query its own transaction
- call_user_func_array( $phpCallback, [ $trigger ] );
+ call_user_func( $phpCallback, $trigger, $this );
if ( $autoTrx ) {
$this->setFlag( self::DBO_TRX ); // restore automatic begin()
} else {
foreach ( $callbacks as $callback ) {
try {
list( $phpCallback ) = $callback;
- call_user_func( $phpCallback );
+ call_user_func( $phpCallback, $this );
} catch ( Exception $ex ) {
call_user_func( $this->errorLogger, $ex );
$e = $e ?: $ex;
*
* @note: do not assume that *other* IDatabase instances will be AUTOCOMMIT mode
*
- * The callback takes one argument:
+ * The callback takes the following arguments:
* - How the transaction ended (IDatabase::TRIGGER_COMMIT or IDatabase::TRIGGER_ROLLBACK)
+ * - This IDatabase instance (since 1.32)
*
* @param callable $callback
* @param string $fname Caller name
*
* @note: do not assume that *other* IDatabase instances will be AUTOCOMMIT mode
*
- * The callback takes one argument:
+ * The callback takes the following arguments:
* - How the transaction ended (IDatabase::TRIGGER_COMMIT or IDatabase::TRIGGER_IDLE)
+ * - This IDatabase instance (since 1.32)
*
* @param callable $callback
* @param string $fname Caller name
*
* Updates will execute in the order they were enqueued.
*
+ * The callback takes the one argument:
+ * - This IDatabase instance (since 1.32)
+ *
* @param callable $callback
* @param string $fname Caller name
* @since 1.22
$logid = $logEntry->insert();
$dbw->onTransactionPreCommitOrIdle(
- function () use ( $dbw, $logEntry, $logid ) {
+ function () use ( $logEntry, $logid ) {
// T58776: avoid deadlocks (especially from FileDeleteForm)
$logEntry->publish( $logid );
},
* @ingroup Profiler
*/
+use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\DBError;
/**
}
$fname = __METHOD__;
- $dbw->onTransactionIdle( function () use ( $stats, $dbw, $fname ) {
+ $dbw->onTransactionIdle( function ( Database $dbw ) use ( $stats, $fname ) {
$pfhost = $this->perHost ? wfHostname() : '';
// Sqlite: avoid excess b-tree rebuilds (mostly for non-WAL mode)
// non-Sqlite: lower contention with small transactions
IDatabase::TRIGGER_COMMIT => 'tCommit',
IDatabase::TRIGGER_ROLLBACK => 'tRollback'
];
+ $pcCallback = function ( IDatabase $db ) use ( $fname ) {
+ $this->database->query( "SELECT 0", $fname );
+ };
$callback1 = function ( $trigger = '-' ) use ( $fname, $triggerMap ) {
$this->database->query( "SELECT 1, {$triggerMap[$trigger]} AS t", $fname );
};
};
$this->database->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE );
- $this->database->onTransactionPreCommitOrIdle( $callback1, __METHOD__ );
+ $this->database->onTransactionPreCommitOrIdle( $pcCallback, __METHOD__ );
$this->database->cancelAtomic( __METHOD__ );
$this->assertLastSql( 'BEGIN; ROLLBACK' );
$this->assertLastSql( 'BEGIN; ROLLBACK; SELECT 1, tRollback AS t' );
$this->database->startAtomic( __METHOD__ . '_outer' );
- $this->database->onTransactionPreCommitOrIdle( $callback1, __METHOD__ );
+ $this->database->onTransactionPreCommitOrIdle( $pcCallback, __METHOD__ );
$this->database->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE );
- $this->database->onTransactionPreCommitOrIdle( $callback2, __METHOD__ );
+ $this->database->onTransactionPreCommitOrIdle( $pcCallback, __METHOD__ );
$this->database->cancelAtomic( __METHOD__ );
- $this->database->onTransactionPreCommitOrIdle( $callback3, __METHOD__ );
+ $this->database->onTransactionPreCommitOrIdle( $pcCallback, __METHOD__ );
$this->database->endAtomic( __METHOD__ . '_outer' );
$this->assertLastSql( implode( "; ", [
'BEGIN',
'SAVEPOINT wikimedia_rdbms_atomic1',
'ROLLBACK TO SAVEPOINT wikimedia_rdbms_atomic1',
- 'SELECT 1, - AS t',
- 'SELECT 3, - AS t',
+ 'SELECT 0',
+ 'SELECT 0',
'COMMIT'
] ) );
$db->clearFlag( DBO_TRX );
$called = false;
$flagSet = null;
- $callback = function () use ( $db, &$flagSet, &$called ) {
+ $callback = function ( $trigger, IDatabase $db ) use ( &$flagSet, &$called ) {
$called = true;
$flagSet = $db->getFlag( DBO_TRX );
};
$db->clearFlag( DBO_TRX );
$db->onTransactionIdle(
- function () use ( $db ) {
+ function ( $trigger, IDatabase $db ) {
$db->setFlag( DBO_TRX );
},
__METHOD__
$called = false;
$db->onTransactionPreCommitOrIdle(
- function () use ( &$called ) {
+ function ( IDatabase $db ) use ( &$called ) {
$called = true;
},
__METHOD__
$db->begin( __METHOD__ );
$called = false;
$db->onTransactionPreCommitOrIdle(
- function () use ( &$called ) {
+ function ( IDatabase $db ) use ( &$called ) {
$called = true;
},
__METHOD__
$this->assertFalse( $lb->hasMasterChanges() );
$this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX is set' );
$called = false;
- $callback = function () use ( &$called ) {
+ $callback = function ( IDatabase $db ) use ( &$called ) {
$called = true;
};
$db->onTransactionPreCommitOrIdle( $callback, __METHOD__ );
$db->clearFlag( DBO_TRX );
$db->begin( __METHOD__ );
$called = false;
- $db->onTransactionResolution( function () use ( $db, &$called ) {
+ $db->onTransactionResolution( function ( $trigger, IDatabase $db ) use ( &$called ) {
$called = true;
$db->setFlag( DBO_TRX );
} );
$db->clearFlag( DBO_TRX );
$db->begin( __METHOD__ );
$called = false;
- $db->onTransactionResolution( function () use ( $db, &$called ) {
+ $db->onTransactionResolution( function ( $trigger, IDatabase $db ) use ( &$called ) {
$called = true;
$db->setFlag( DBO_TRX );
} );