MediaWiki master
MWCallableUpdate.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Deferred;
4
5use Closure;
8
16{
18 private $callback;
20 private $fname;
22 private $trxRoundRequirement = self::TRX_ROUND_PRESENT;
23
34 public function __construct(
35 callable $callback,
36 $fname = ISQLPlatform::CALLER_UNKNOWN,
37 $dependeeDbws = []
38 ) {
39 $this->callback = $callback;
40 $this->fname = $fname;
41
42 $dependeeDbws = is_array( $dependeeDbws ) ? $dependeeDbws : [ $dependeeDbws ];
43 foreach ( $dependeeDbws as $dbw ) {
44 if ( $dbw->trxLevel() ) {
45 $dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
46 }
47 }
48 }
49
50 public function doUpdate() {
51 if ( $this->callback instanceof Closure ) {
52 ( $this->callback )( $this->fname );
53 } elseif ( $this->callback ) {
54 // For backwards-compatibility with [$classOrObject, 'func'] style callbacks
55 // where the function happened to already take an optional parameter.
56 ( $this->callback )();
57 }
58 }
59
64 public function cancelOnRollback( $trigger ) {
65 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
66 $this->callback = null;
67 }
68 }
69
70 public function getOrigin() {
71 return $this->fname;
72 }
73
77 public function setTransactionRoundRequirement( $mode ) {
78 $this->trxRoundRequirement = $mode;
79 }
80
82 return $this->trxRoundRequirement;
83 }
84}
85
87class_alias( MWCallableUpdate::class, 'MWCallableUpdate' );
DeferrableUpdate for closure/callable.
__construct(callable $callback, $fname=ISQLPlatform::CALLER_UNKNOWN, $dependeeDbws=[])
doUpdate()
Perform the actual work.
Callback wrapper that has an originating method.
Interface that deferrable updates should implement.
Deferrable update that specifies whether it must run outside of any explicit LBFactory transaction ro...
Interface to a relational database.
Definition IDatabase.php:45
Interface for query language.