* @file
* @ingroup Maintenance
*/
+
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\IDatabase;
+
class BatchRowWriter {
/**
* @var IDatabase $db The database to write to
/**
* @param IDatabase $db The database to write to
- * @param string $table The name of the table to update
- * @param string|bool $clusterName A cluster name valid for use with LBFactory
+ * @param string $table The name of the table to update
+ * @param string|bool $clusterName A cluster name valid for use with LBFactory
*/
public function __construct( IDatabase $db, $table, $clusterName = false ) {
$this->db = $db;
* names to update values to apply to the row.
*/
public function write( array $updates ) {
- $this->db->begin();
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
foreach ( $updates as $update ) {
$this->db->update(
);
}
- $this->db->commit();
- wfGetLBFactory()->waitForReplication();
+ $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
}
}