Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / deferred / AtomicSectionUpdate.php
1 <?php
2
3 /**
4 * Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
5 * @since 1.27
6 */
7 class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
8 /** @var IDatabase */
9 private $dbw;
10 /** @var string */
11 private $fname;
12 /** @var callable|null */
13 private $callback;
14
15 /**
16 * @param IDatabase $dbw
17 * @param string $fname Caller name (usually __METHOD__)
18 * @param callable $callback
19 * @see IDatabase::doAtomicSection()
20 */
21 public function __construct( IDatabase $dbw, $fname, callable $callback ) {
22 $this->dbw = $dbw;
23 $this->fname = $fname;
24 $this->callback = $callback;
25
26 if ( $this->dbw->trxLevel() ) {
27 $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
28 }
29 }
30
31 public function doUpdate() {
32 if ( $this->callback ) {
33 $this->dbw->doAtomicSection( $this->fname, $this->callback );
34 }
35 }
36
37 public function cancelOnRollback( $trigger ) {
38 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
39 $this->callback = null;
40 }
41 }
42
43 public function getOrigin() {
44 return $this->fname;
45 }
46 }