Merge "Title: Simplify use of MWNamespace::getCanonicalName()"
[lhc/web/wiklou.git] / includes / utils / BatchRowWriter.php
index ffb7053..c146e96 100644 (file)
  * @file
  * @ingroup Maintenance
  */
+
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\IDatabase;
+
 class BatchRowWriter {
        /**
         * @var IDatabase $db The database to write to
@@ -38,8 +42,8 @@ class BatchRowWriter {
 
        /**
         * @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;
@@ -54,7 +58,8 @@ class BatchRowWriter {
         *  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(
@@ -65,7 +70,6 @@ class BatchRowWriter {
                        );
                }
 
-               $this->db->commit();
-               wfGetLBFactory()->waitForReplication();
+               $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
        }
 }