MediaWiki  master
BatchRowWriter.php
Go to the documentation of this file.
1 <?php
26 
31  protected $db;
32 
36  protected $table;
37 
41  protected $clusterName;
42 
46  protected $caller;
47 
53  public function __construct( IDatabase $db, $table, $clusterName = false ) {
54  $this->db = $db;
55  $this->table = $table;
56  $this->clusterName = $clusterName;
57  }
58 
67  public function setCaller( $caller ) {
68  $this->caller = $caller;
69  return $this;
70  }
71 
79  public function write( array $updates ) {
80  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
81  $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
82 
83  $caller = __METHOD__;
84  if ( (string)$this->caller !== '' ) {
85  $caller .= " (for {$this->caller})";
86  }
87 
88  foreach ( $updates as $update ) {
89  $this->db->newUpdateQueryBuilder()
90  ->update( $this->table )
91  ->set( $update['changes'] )
92  ->where( $update['primaryKey'] )
93  ->caller( $caller )->execute();
94  }
95 
96  $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
97  }
98 }
string null $caller
For debugging which method is using this class.
__construct(IDatabase $db, $table, $clusterName=false)
write(array $updates)
setCaller( $caller)
Use ->setCaller( METHOD ) to indicate which code is using this class.
string false $clusterName
A cluster name valid for use with LBFactory.
IDatabase $db
The database to write to.
string $table
The name of the table to update.
Service locator for MediaWiki core services.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:36