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->update(
90  $this->table,
91  $update['changes'],
92  $update['primaryKey'],
93  $caller
94  );
95  }
96 
97  $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
98  }
99 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
BatchRowWriter\$table
string $table
The name of the table to update.
Definition: BatchRowWriter.php:36
BatchRowWriter\write
write(array $updates)
Definition: BatchRowWriter.php:79
BatchRowWriter\__construct
__construct(IDatabase $db, $table, $clusterName=false)
Definition: BatchRowWriter.php:53
BatchRowWriter
Definition: BatchRowWriter.php:27
BatchRowWriter\setCaller
setCaller( $caller)
Use ->setCaller( METHOD ) to indicate which code is using this class.
Definition: BatchRowWriter.php:67
BatchRowWriter\$caller
string null $caller
For debugging which method is using this class.
Definition: BatchRowWriter.php:46
BatchRowWriter\$db
IDatabase $db
The database to write to.
Definition: BatchRowWriter.php:31
BatchRowWriter\$clusterName
string false $clusterName
A cluster name valid for use with LBFactory.
Definition: BatchRowWriter.php:41