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
19 * @param string $fname Caller name (usually __METHOD__)
20 * @param callable $callback
21 * @see IDatabase::doAtomicSection()
23 public function __construct( IDatabase
$dbw, $fname, callable
$callback ) {
25 $this->fname
= $fname;
26 $this->callback
= $callback;
28 if ( $this->dbw
->trxLevel() ) {
29 $this->dbw
->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
33 public function doUpdate() {
34 if ( $this->callback
) {
35 $this->dbw
->doAtomicSection( $this->fname
, $this->callback
);
39 public function cancelOnRollback( $trigger ) {
40 if ( $trigger === IDatabase
::TRIGGER_ROLLBACK
) {
41 $this->callback
= null;
45 public function getOrigin() {