Special case opus mime detction
[mediawiki.git] / includes / deferred / MWCallableUpdate.php
blob5247e97cf10682fcbb9fdaca787a750bb633d9de
1 <?php
3 /**
4 * Deferrable Update for closure/callback
5 */
6 class MWCallableUpdate implements DeferrableUpdate, DeferrableCallback {
7 /** @var callable|null */
8 private $callback;
9 /** @var string */
10 private $fname;
12 /**
13 * @param callable $callback
14 * @param string $fname Calling method
15 * @param IDatabase|null $dbw Abort if this DB is rolled back [optional] (since 1.28)
17 public function __construct( callable $callback, $fname = 'unknown', IDatabase $dbw = null ) {
18 $this->callback = $callback;
19 $this->fname = $fname;
21 if ( $dbw && $dbw->trxLevel() ) {
22 $dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
26 public function doUpdate() {
27 if ( $this->callback ) {
28 call_user_func( $this->callback );
32 public function cancelOnRollback( $trigger ) {
33 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
34 $this->callback = null;
38 public function getOrigin() {
39 return $this->fname;