4 * Deferrable Update for closure/callback updates that should use auto-commit mode
7 class AutoCommitUpdate
implements DeferrableUpdate
, DeferrableCallback
{
12 /** @var callable|null */
16 * @param IDatabase $dbw
17 * @param string $fname Caller name (usually __METHOD__)
18 * @param callable $callback Callback that takes (IDatabase, method name string)
20 public function __construct( IDatabase
$dbw, $fname, callable
$callback ) {
22 $this->fname
= $fname;
23 $this->callback
= $callback;
25 if ( $this->dbw
->trxLevel() ) {
26 $this->dbw
->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
30 public function doUpdate() {
31 if ( !$this->callback
) {
35 $autoTrx = $this->dbw
->getFlag( DBO_TRX
);
36 $this->dbw
->clearFlag( DBO_TRX
);
38 /** @var Exception $e */
40 call_user_func_array( $this->callback
, [ $this->dbw
, $this->fname
] );
41 } catch ( Exception
$e ) {
44 $this->dbw
->setFlag( DBO_TRX
);
51 public function cancelOnRollback( $trigger ) {
52 if ( $trigger === IDatabase
::TRIGGER_ROLLBACK
) {
53 $this->callback
= null;
57 public function getOrigin() {