3 use Wikimedia\Rdbms\IDatabase
;
6 * Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
9 class AtomicSectionUpdate
implements DeferrableUpdate
, DeferrableCallback
{
14 /** @var callable|null */
18 * @param IDatabase $dbw DB handle; update aborts if a transaction now this rolls back
19 * @param string $fname Caller name (usually __METHOD__)
20 * @param callable $callback
21 * @param IDatabase[] $conns Abort if a transaction now on one of these rolls back [optional]
22 * @see IDatabase::doAtomicSection()
24 public function __construct( IDatabase
$dbw, $fname, callable
$callback, array $conns = [] ) {
26 $this->fname
= $fname;
27 $this->callback
= $callback;
28 // Register DB connections for which uncommitted changes are related to this update
30 foreach ( $conns as $conn ) {
31 if ( $conn->trxLevel() ) {
32 $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
37 public function doUpdate() {
38 if ( $this->callback
) {
39 $this->dbw
->doAtomicSection( $this->fname
, $this->callback
);
44 * @private This method is public so that it works with onTransactionResolution()
47 public function cancelOnRollback( $trigger ) {
48 if ( $trigger === IDatabase
::TRIGGER_ROLLBACK
) {
49 $this->callback
= null;
53 public function getOrigin() {