2016-01-13 16:54:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
2016-07-22 02:32:09 +00:00
|
|
|
class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
|
2016-01-13 16:54:48 +00:00
|
|
|
/** @var IDatabase */
|
|
|
|
|
private $dbw;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $fname;
|
2016-07-19 20:43:17 +00:00
|
|
|
/** @var callable */
|
2016-01-13 16:54:48 +00:00
|
|
|
private $callback;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param IDatabase $dbw
|
|
|
|
|
* @param string $fname Caller name (usually __METHOD__)
|
|
|
|
|
* @param callable $callback
|
|
|
|
|
* @see IDatabase::doAtomicSection()
|
|
|
|
|
*/
|
2016-07-19 20:43:17 +00:00
|
|
|
public function __construct( IDatabase $dbw, $fname, callable $callback ) {
|
2016-01-13 16:54:48 +00:00
|
|
|
$this->dbw = $dbw;
|
|
|
|
|
$this->fname = $fname;
|
|
|
|
|
$this->callback = $callback;
|
2016-07-19 20:43:17 +00:00
|
|
|
|
|
|
|
|
if ( $this->dbw->trxLevel() ) {
|
|
|
|
|
$this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ] );
|
|
|
|
|
}
|
2016-01-13 16:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doUpdate() {
|
2016-07-19 20:43:17 +00:00
|
|
|
if ( $this->callback ) {
|
|
|
|
|
$this->dbw->doAtomicSection( $this->fname, $this->callback );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function cancelOnRollback( $trigger ) {
|
|
|
|
|
if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
|
|
|
|
|
$this->callback = null;
|
|
|
|
|
}
|
2016-01-13 16:54:48 +00:00
|
|
|
}
|
2016-07-22 02:32:09 +00:00
|
|
|
|
|
|
|
|
public function getOrigin() {
|
|
|
|
|
return $this->fname;
|
|
|
|
|
}
|
2016-01-13 16:54:48 +00:00
|
|
|
}
|