* @since 1.20
*/
final public function onTransactionIdle( $callback ) {
- $this->mTrxIdleCallbacks[] = $callback;
+ $this->mTrxIdleCallbacks[] = array( $callback, wfGetCaller() );
if ( !$this->mTrxLevel ) {
$this->runOnTransactionIdleCallbacks();
}
*/
final public function onTransactionPreCommitOrIdle( $callback ) {
if ( $this->mTrxLevel ) {
- $this->mTrxPreCommitCallbacks[] = $callback;
+ $this->mTrxPreCommitCallbacks[] = array( $callback, wfGetCaller() );
} else {
$this->onTransactionIdle( $callback ); // this will trigger immediately
}
$this->mTrxIdleCallbacks = array(); // recursion guard
foreach ( $callbacks as $callback ) {
try {
+ list( $phpCallback ) = $callback;
$this->clearFlag( DBO_TRX ); // make each query its own transaction
- call_user_func( $callback );
+ call_user_func( $phpCallback );
$this->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
} catch ( Exception $e ) {}
}
$this->mTrxPreCommitCallbacks = array(); // recursion guard
foreach ( $callbacks as $callback ) {
try {
- call_user_func( $callback );
+ list( $phpCallback ) = $callback;
+ call_user_func( $phpCallback );
} catch ( Exception $e ) {}
}
} while ( count( $this->mTrxPreCommitCallbacks ) );
if ( $this->mTrxDoneWrites ) {
Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname );
}
+ $this->mTrxDoneWrites = false;
$this->runOnTransactionIdleCallbacks();
}
if ( $this->mTrxDoneWrites ) {
Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname );
}
+ $this->mTrxDoneWrites = false;
}
/**
return (string)$this->mConn;
}
+ /**
+ * Run a few simple sanity checks
+ */
public function __destruct() {
+ if ( $this->mTrxLevel && $this->mTrxDoneWrites ) {
+ trigger_error( "Uncommitted DB writes (transaction from {$this->mTrxFname})." );
+ }
if ( count( $this->mTrxIdleCallbacks ) || count( $this->mTrxPreCommitCallbacks ) ) {
- trigger_error( "Transaction idle or pre-commit callbacks still pending." ); // sanity
+ $callers = array();
+ foreach ( $this->mTrxIdleCallbacks as $callbackInfo ) {
+ $callers[] = $callbackInfo[0];
+
+ }
+ $callers = implode( ', ', $callers );
+ trigger_error( "DB transaction callbacks still pending (from $callers)." );
}
}
}