* @param $recursive Boolean: queue jobs for recursive updates?
*/
function __construct( $title, $parserOutput, $recursive = true ) {
- parent::__construct( );
+ parent::__construct( false ); // no implicit transaction
if ( !( $title instanceof Title ) ) {
throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
* @param $page WikiPage Page we are updating
*/
function __construct( WikiPage $page ) {
- parent::__construct( );
+ parent::__construct( false ); // no implicit transaction
$this->mPage = $page;
}
protected $mOptions; //!< SELECT options to be used (array)
private $mHasTransaction; //!< bool whether a transaction is open on this object (internal use only!)
+ protected $mUseTransaction; //!< bool whether this update should be wrapped in a transaction
/**
* Constructor
- **/
- public function __construct( ) {
+ *
+ * @param bool $withTransaction whether this update should be wrapped in a transaction (default: true).
+ * A transaction is only started if no transaction is already in progress,
+ * see beginTransaction() for details.
+ **/
+ public function __construct( $withTransaction = true ) {
global $wgAntiLockFlags;
parent::__construct( );
// @todo: get connection only when it's needed? make sure that doesn't break anything, especially transactions!
$this->mDb = wfGetDB( DB_MASTER );
+
+ $this->mWithTransaction = $withTransaction;
$this->mHasTransaction = false;
}
/**
- * Begin a database transaction.
+ * Begin a database transaction, if $withTransaction was given as true in the constructor for this SqlDataUpdate.
*
- * Because nested transactions are not supportred by the Database class, this implementation
- * checkes Database::trxLevel() and only opens a transaction if none is yet active.
+ * Because nested transactions are not supported by the Database class, this implementation
+ * checks Database::trxLevel() and only opens a transaction if none is already active.
*/
public function beginTransaction() {
+ if ( !$this->mWithTransaction ) {
+ return;
+ }
+
// NOTE: nested transactions are not supported, only start a transaction if none is open
if ( $this->mDb->trxLevel() === 0 ) {
$this->mDb->begin( get_class( $this ) . '::beginTransaction' );
public function commitTransaction() {
if ( $this->mHasTransaction ) {
$this->mDb->commit( get_class( $this ) . '::commitTransaction' );
+ $this->mHasTransaction = false;
}
}
public function abortTransaction() {
if ( $this->mHasTransaction ) {
$this->mDb->rollback( get_class( $this ) . '::abortTransaction' );
+ $this->mHasTransaction = false;
}
}