X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSqlDataUpdate.php;h=d0ead9ad8b2207f19f769b5c4240b925c98229e2;hb=0c1f2232474ad09da94979acd9de36b495642fdd;hp=aeb9ba4c7f66a007142cf30e5983bd8f24ae7e30;hpb=eeb7300f6004e95620514eb9bac508425e94f197;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SqlDataUpdate.php b/includes/SqlDataUpdate.php index aeb9ba4c7f..d0ead9ad8b 100644 --- a/includes/SqlDataUpdate.php +++ b/includes/SqlDataUpdate.php @@ -36,11 +36,16 @@ abstract class SqlDataUpdate extends DataUpdate { 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( ); @@ -53,16 +58,22 @@ abstract class SqlDataUpdate extends DataUpdate { // @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' ); @@ -76,6 +87,7 @@ abstract class SqlDataUpdate extends DataUpdate { public function commitTransaction() { if ( $this->mHasTransaction ) { $this->mDb->commit( get_class( $this ) . '::commitTransaction' ); + $this->mHasTransaction = false; } } @@ -83,8 +95,9 @@ abstract class SqlDataUpdate extends DataUpdate { * Abort the database transaction started via beginTransaction (if any). */ public function abortTransaction() { - if ( $this->mHasTransaction ) { + if ( $this->mHasTransaction ) { //XXX: actually... maybe always? $this->mDb->rollback( get_class( $this ) . '::abortTransaction' ); + $this->mHasTransaction = false; } } @@ -95,8 +108,8 @@ abstract class SqlDataUpdate extends DataUpdate { * @param $namespace Integer * @param $dbkeys Array */ - protected function invalidatePages( $namespace, Array $dbkeys ) { - if ( !count( $dbkeys ) ) { + protected function invalidatePages( $namespace, array $dbkeys ) { + if ( $dbkeys === array() ) { return; } @@ -114,10 +127,12 @@ abstract class SqlDataUpdate extends DataUpdate { 'page_touched < ' . $this->mDb->addQuotes( $now ) ), __METHOD__ ); + foreach ( $res as $row ) { $ids[] = $row->page_id; } - if ( !count( $ids ) ) { + + if ( $ids === array() ) { return; }