Special case opus mime detction
[mediawiki.git] / includes / deferred / AtomicSectionUpdate.php
blob6585575dc352f307a741ef02a5af56a34e8fa9ab
1 <?php
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;
15 /**
16 * @param IDatabase $dbw
17 * @param string $fname Caller name (usually __METHOD__)
18 * @param callable $callback
19 * @see IDatabase::doAtomicSection()
21 public function __construct( IDatabase $dbw, $fname, callable $callback ) {
22 $this->dbw = $dbw;
23 $this->fname = $fname;
24 $this->callback = $callback;
26 if ( $this->dbw->trxLevel() ) {
27 $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
31 public function doUpdate() {
32 if ( $this->callback ) {
33 $this->dbw->doAtomicSection( $this->fname, $this->callback );
37 public function cancelOnRollback( $trigger ) {
38 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
39 $this->callback = null;
43 public function getOrigin() {
44 return $this->fname;