MediaWiki master
BatchRowWriter.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Utils;
11
14
19 protected $db;
20
24 protected $table;
25
29 protected $clusterName;
30
34 protected $caller;
35
41 public function __construct( IDatabase $db, $table, $clusterName = false ) {
42 $this->db = $db;
43 $this->table = $table;
44 $this->clusterName = $clusterName;
45 }
46
55 public function setCaller( $caller ) {
56 $this->caller = $caller;
57 return $this;
58 }
59
67 public function write( array $updates ) {
68 $dbProvider = MediaWikiServices::getInstance()->getConnectionProvider();
69 $ticket = $dbProvider->getEmptyTransactionTicket( __METHOD__ );
70
71 $caller = __METHOD__;
72 if ( (string)$this->caller !== '' ) {
73 $caller .= " (for {$this->caller})";
74 }
75
76 foreach ( $updates as $update ) {
77 $this->db->newUpdateQueryBuilder()
78 ->update( $this->table )
79 ->set( $update['changes'] )
80 ->where( $update['primaryKey'] )
81 ->caller( $caller )->execute();
82 }
83
84 $dbProvider->commitAndWaitForReplication( __METHOD__, $ticket );
85 }
86}
87
89class_alias( BatchRowWriter::class, 'BatchRowWriter' );
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
string false $clusterName
A cluster name valid for use with LBFactory.
setCaller( $caller)
Use ->setCaller( METHOD ) to indicate which code is using this class.
IDatabase $db
The database to write to.
string $table
The name of the table to update.
__construct(IDatabase $db, $table, $clusterName=false)
string null $caller
For debugging which method is using this class.
Interface to a relational database.
Definition IDatabase.php:31
Copyright (C) 2017 Kunal Mehta legoktm@debian.org