34 private $updateRowsPerQuery;
45 parent::__construct(
'renameUser', $title,
$params );
47 $this->updateRowsPerQuery = $config->
get( MainConfigNames::UpdateRowsPerQuery );
48 $this->lbFactory = $lbFactory;
51 public function run() {
52 $dbw = $this->lbFactory->getPrimaryDatabase();
53 $table = $this->params[
'table'];
54 $column = $this->params[
'column'];
56 $oldname = $this->params[
'oldname'];
57 $newname = $this->params[
'newname'];
58 if ( isset( $this->params[
'userID'] ) ) {
59 $userID = $this->params[
'userID'];
60 $uidColumn = $this->params[
'uidColumn'];
65 if ( isset( $this->params[
'timestampColumn'] ) ) {
66 $timestampColumn = $this->params[
'timestampColumn'];
67 $minTimestamp = $this->params[
'minTimestamp'];
68 $maxTimestamp = $this->params[
'maxTimestamp'];
70 $timestampColumn =
null;
74 $uniqueKey = $this->params[
'uniqueKey'] ??
null;
75 $keyId = $this->params[
'keyId'] ??
null;
77 # Conditions like "*_user_text = 'x'
78 $conds = [ $column => $oldname ];
79 # If user ID given, add that to condition to avoid rename collisions
80 if ( $userID !== null ) {
81 $conds[$uidColumn] = $userID;
83 # Bound by timestamp if given
84 if ( $timestampColumn !== null ) {
85 $conds[] = $dbw->expr( $timestampColumn, '>=', $minTimestamp );
86 $conds[] = $dbw->expr( $timestampColumn, '<=', $maxTimestamp );
87 # Bound by unique key if given (B/C)
88 } elseif ( $uniqueKey !== null && $keyId !== null ) {
89 $conds[$uniqueKey] = $keyId;
91 throw new InvalidArgumentException( 'Expected ID batch or time range' );
94 # Actually update the rows for this job...
95 if ( $uniqueKey !== null ) {
96 // Select the rows to update by PRIMARY KEY
97 $ids = $dbw->newSelectQueryBuilder()
98 ->select( $uniqueKey )
101 ->caller( __METHOD__ )->fetchFieldValues();
102 # Update these rows by PRIMARY KEY to avoid replica lag
103 foreach ( array_chunk( $ids, $this->updateRowsPerQuery ) as $batch ) {
104 $dbw->commit( __METHOD__, 'flush' );
105 $this->lbFactory->waitForReplication();
107 $dbw->newUpdateQueryBuilder()
109 ->set( [ $column => $newname ] )
110 ->where( [ $column => $oldname, $uniqueKey => $batch ] )
111 ->caller( __METHOD__ )->execute();
114 # Update the chunk of rows directly
115 $dbw->newUpdateQueryBuilder()
117 ->set( [ $column => $newname ] )
119 ->caller( __METHOD__ )->execute();
array $params
The job parameters.
Describe and execute a background job.
A class containing constants representing the names of configuration variables.
Custom job to perform updates on tables in busier environments.
__construct(Title $title, $params, Config $config, ILBFactory $lbFactory)