$this->uncacheLinkTarget( $target );
$this->reuseConnection( $dbw );
- }
+ },
+ DeferredUpdates::POSTSEND,
+ $dbw
);
}
'pageStatus' => 'changed'
];
- DeferredUpdates::addCallableUpdate( function() use ( $rc, $tags ) {
- $rc->save();
- if ( $rc->mAttribs['rc_patrolled'] ) {
- PatrolLog::record( $rc, true, $rc->getPerformer() );
- }
- if ( count( $tags ) ) {
- ChangeTags::addTags( $tags, $rc->mAttribs['rc_id'],
- $rc->mAttribs['rc_this_oldid'], null, null );
- }
- } );
+ DeferredUpdates::addCallableUpdate(
+ function () use ( $rc, $tags ) {
+ $rc->save();
+ if ( $rc->mAttribs['rc_patrolled'] ) {
+ PatrolLog::record( $rc, true, $rc->getPerformer() );
+ }
+ if ( count( $tags ) ) {
+ ChangeTags::addTags( $tags, $rc->mAttribs['rc_id'],
+ $rc->mAttribs['rc_this_oldid'], null, null );
+ }
+ },
+ DeferredUpdates::POSTSEND,
+ wfGetDB( DB_MASTER )
+ );
return $rc;
}
'pageStatus' => 'created'
];
- DeferredUpdates::addCallableUpdate( function() use ( $rc, $tags ) {
- $rc->save();
- if ( $rc->mAttribs['rc_patrolled'] ) {
- PatrolLog::record( $rc, true, $rc->getPerformer() );
- }
- if ( count( $tags ) ) {
- ChangeTags::addTags( $tags, $rc->mAttribs['rc_id'],
- $rc->mAttribs['rc_this_oldid'], null, null );
- }
- } );
+ DeferredUpdates::addCallableUpdate(
+ function () use ( $rc, $tags ) {
+ $rc->save();
+ if ( $rc->mAttribs['rc_patrolled'] ) {
+ PatrolLog::record( $rc, true, $rc->getPerformer() );
+ }
+ if ( count( $tags ) ) {
+ ChangeTags::addTags( $tags, $rc->mAttribs['rc_id'],
+ $rc->mAttribs['rc_this_oldid'], null, null );
+ }
+ },
+ DeferredUpdates::POSTSEND,
+ wfGetDB( DB_MASTER )
+ );
return $rc;
}
private $dbw;
/** @var string */
private $fname;
- /** @var callable */
+ /** @var callable|null */
private $callback;
/**
private $dbw;
/** @var string */
private $fname;
- /** @var callable */
+ /** @var callable|null */
private $callback;
/**
*
* @param callable $callable
* @param integer $type DeferredUpdates constant (PRESEND or POSTSEND) (since 1.27)
+ * @param IDatabase|null $dbw Abort if this DB is rolled back [optional] (since 1.28)
*/
- public static function addCallableUpdate( $callable, $type = self::POSTSEND ) {
- self::addUpdate( new MWCallableUpdate( $callable, wfGetCaller() ), $type );
+ public static function addCallableUpdate(
+ $callable, $type = self::POSTSEND, IDatabase $dbw = null
+ ) {
+ self::addUpdate( new MWCallableUpdate( $callable, wfGetCaller(), $dbw ), $type );
}
/**
* Deferrable Update for closure/callback
*/
class MWCallableUpdate implements DeferrableUpdate, DeferrableCallback {
- /** @var callable */
+ /** @var callable|null */
private $callback;
/** @var string */
private $fname;
/**
* @param callable $callback
* @param string $fname Calling method
+ * @param IDatabase|null $dbw Abort if this DB is rolled back [optional] (since 1.28)
*/
- public function __construct( callable $callback, $fname = 'unknown' ) {
+ public function __construct( callable $callback, $fname = 'unknown', IDatabase $dbw = null ) {
$this->callback = $callback;
$this->fname = $fname;
+
+ if ( $dbw && $dbw->trxLevel() ) {
+ $dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ] );
+ }
}
public function doUpdate() {
- call_user_func( $this->callback );
+ if ( $this->callback ) {
+ call_user_func( $this->callback );
+ }
+ }
+
+ public function cancelOnRollback( $trigger ) {
+ if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
+ $this->callback = null;
+ }
}
public function getOrigin() {
// Update the DB post-send if the page has not cached since now
$that = $this;
$latest = $this->getLatest();
- DeferredUpdates::addCallableUpdate( function() use ( $that, $retval, $latest ) {
- $that->insertRedirectEntry( $retval, $latest );
- } );
+ DeferredUpdates::addCallableUpdate(
+ function () use ( $that, $retval, $latest ) {
+ $that->insertRedirectEntry( $retval, $latest );
+ },
+ DeferredUpdates::POSTSEND,
+ wfGetDB( DB_MASTER )
+ );
return $retval;
}
function () use ( $visibilityChangeMap ) {
$this->doPostCommitUpdates( $visibilityChangeMap );
},
- DeferredUpdates::PRESEND
+ DeferredUpdates::PRESEND,
+ $dbw
);
$dbw->endAtomic( __METHOD__ );