MediaWiki REL1_34
AutoCommitUpdate.php
Go to the documentation of this file.
1<?php
2
4
11 private $dbw;
13 private $fname;
15 private $callback;
16
23 public function __construct( IDatabase $dbw, $fname, callable $callback, array $conns = [] ) {
24 $this->dbw = $dbw;
25 $this->fname = $fname;
26 $this->callback = $callback;
27 // Register DB connections for which uncommitted changes are related to this update
28 $conns[] = $dbw;
29 foreach ( $conns as $conn ) {
30 if ( $conn->trxLevel() ) {
31 $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
32 }
33 }
34 }
35
36 public function doUpdate() {
37 if ( !$this->callback ) {
38 return;
39 }
40
41 $autoTrx = $this->dbw->getFlag( DBO_TRX );
42 $this->dbw->clearFlag( DBO_TRX );
43 try {
45 $e = null;
46 ( $this->callback )( $this->dbw, $this->fname );
47 } catch ( Exception $e ) {
48 }
49 if ( $autoTrx ) {
50 $this->dbw->setFlag( DBO_TRX );
51 }
52 if ( $e ) {
53 throw $e;
54 }
55 }
56
61 public function cancelOnRollback( $trigger ) {
62 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
63 $this->callback = null;
64 }
65 }
66
67 public function getOrigin() {
68 return $this->fname;
69 }
70}
Deferrable Update for closure/callback updates that should use auto-commit mode.
callable null $callback
doUpdate()
Perform the actual work.
cancelOnRollback( $trigger)
__construct(IDatabase $dbw, $fname, callable $callback, array $conns=[])
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:38
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback as soon as the current transaction commits or rolls back.
const DBO_TRX
Definition defines.php:12