MediaWiki 1.42.1
AutoCommitUpdate.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Deferred;
4
6
13 private $dbw;
15 private $fname;
17 private $callback;
18
26 public function __construct( IDatabase $dbw, $fname, callable $callback, array $conns = [] ) {
27 $this->dbw = $dbw;
28 $this->fname = $fname;
29 $this->callback = $callback;
30 // Register DB connections for which uncommitted changes are related to this update
31 $conns[] = $dbw;
32 foreach ( $conns as $conn ) {
33 if ( $conn->trxLevel() ) {
34 $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
35 }
36 }
37 }
38
39 public function doUpdate() {
40 if ( !$this->callback ) {
41 return;
42 }
43
44 $autoTrx = $this->dbw->getFlag( DBO_TRX );
45 $this->dbw->clearFlag( DBO_TRX );
46 try {
47 ( $this->callback )( $this->dbw, $this->fname );
48 } finally {
49 if ( $autoTrx ) {
50 $this->dbw->setFlag( DBO_TRX );
51 }
52 }
53 }
54
59 public function cancelOnRollback( $trigger ) {
60 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
61 $this->callback = null;
62 }
63 }
64
65 public function getOrigin() {
66 return $this->fname;
67 }
68}
69
71class_alias( AutoCommitUpdate::class, 'AutoCommitUpdate' );
Deferrable Update for closure/callback updates that should use auto-commit mode.
__construct(IDatabase $dbw, $fname, callable $callback, array $conns=[])
doUpdate()
Perform the actual work.
Callback wrapper that has an originating method.
Interface that deferrable updates should implement.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or rolls back.
const DBO_TRX
Definition defines.php:12