3 namespace MediaWiki\Deferred
;
5 use Wikimedia\Rdbms\IDatabase
;
8 * Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
11 class AtomicSectionUpdate
implements DeferrableUpdate
, DeferrableCallback
{
16 /** @var callable|null */
20 * @see IDatabase::doAtomicSection()
21 * @param IDatabase $dbw DB handle; update aborts if a transaction now this rolls back
22 * @param string $fname Caller name (usually __METHOD__)
23 * @param callable $callback
24 * @param IDatabase[] $conns Cancel the update if a DB transaction is rolled back [optional]
26 public function __construct( IDatabase
$dbw, $fname, callable
$callback, array $conns = [] ) {
28 $this->fname
= $fname;
29 $this->callback
= $callback;
30 // Register DB connections for which uncommitted changes are related to this update
32 foreach ( $conns as $conn ) {
33 if ( $conn->trxLevel() ) {
34 $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
39 public function doUpdate() {
40 if ( $this->callback
) {
41 $this->dbw
->doAtomicSection( $this->fname
, $this->callback
);
46 * @internal This method is public so that it works with onTransactionResolution()
49 public function cancelOnRollback( $trigger ) {
50 if ( $trigger === IDatabase
::TRIGGER_ROLLBACK
) {
51 $this->callback
= null;
55 public function getOrigin() {
60 /** @deprecated class alias since 1.42 */
61 class_alias( AtomicSectionUpdate
::class, 'AtomicSectionUpdate' );