MediaWiki REL1_31
AutoCommitUpdate.php
Go to the documentation of this file.
1<?php
2
4
11 private $dbw;
13 private $fname;
15 private $callback;
16
22 public function __construct( IDatabase $dbw, $fname, callable $callback ) {
23 $this->dbw = $dbw;
24 $this->fname = $fname;
25 $this->callback = $callback;
26
27 if ( $this->dbw->trxLevel() ) {
28 $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
29 }
30 }
31
32 public function doUpdate() {
33 if ( !$this->callback ) {
34 return;
35 }
36
37 $autoTrx = $this->dbw->getFlag( DBO_TRX );
38 $this->dbw->clearFlag( DBO_TRX );
39 try {
41 $e = null;
42 call_user_func_array( $this->callback, [ $this->dbw, $this->fname ] );
43 } catch ( Exception $e ) {
44 }
45 if ( $autoTrx ) {
46 $this->dbw->setFlag( DBO_TRX );
47 }
48 if ( $e ) {
49 throw $e;
50 }
51 }
52
53 public function cancelOnRollback( $trigger ) {
54 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
55 $this->callback = null;
56 }
57 }
58
59 public function getOrigin() {
60 return $this->fname;
61 }
62}
Deferrable Update for closure/callback updates that should use auto-commit mode.
__construct(IDatabase $dbw, $fname, callable $callback)
callable null $callback
doUpdate()
Perform the actual work.
cancelOnRollback( $trigger)
returning false will NOT prevent logging $e
Definition hooks.txt:2176
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
const DBO_TRX
Definition defines.php:12