57 public function run() {
58 $dbw = $this->lbFactory->getMainLB()->getMaintenanceConnectionRef(
DB_PRIMARY );
59 $table = $this->params[
'table'];
60 $column = $this->params[
'column'];
64 if ( !$dbw->tableExists( $table, __METHOD__ ) ) {
66 "Ignoring job {$this->toString()}, table $table does not exist" );
68 } elseif ( !$dbw->fieldExists( $table, $column, __METHOD__ ) ) {
70 "Ignoring job {$this->toString()}, column $table.$column does not exist" );
74 $oldname = $this->params[
'oldname'];
75 $newname = $this->params[
'newname'];
76 if ( isset( $this->params[
'userID'] ) ) {
77 $userID = $this->params[
'userID'];
78 $uidColumn = $this->params[
'uidColumn'];
83 if ( isset( $this->params[
'timestampColumn'] ) ) {
84 $timestampColumn = $this->params[
'timestampColumn'];
85 $minTimestamp = $this->params[
'minTimestamp'];
86 $maxTimestamp = $this->params[
'maxTimestamp'];
88 $timestampColumn =
null;
92 $uniqueKey = $this->params[
'uniqueKey'] ??
null;
93 $keyId = $this->params[
'keyId'] ??
null;
95 # Conditions like "*_user_text = 'x'
96 $conds = [ $column => $oldname ];
97 # If user ID given, add that to condition to avoid rename collisions
98 if ( $userID !== null ) {
99 $conds[$uidColumn] = $userID;
101 # Bound by timestamp if given
102 if ( $timestampColumn !== null ) {
103 $conds[] = "$timestampColumn >= " . $dbw->addQuotes( $minTimestamp );
104 $conds[] = "$timestampColumn <= " . $dbw->addQuotes( $maxTimestamp );
105 # Bound by unique key if given (B/C)
106 } elseif ( $uniqueKey !== null && $keyId !== null ) {
107 $conds[$uniqueKey] = $keyId;
109 throw new InvalidArgumentException( 'Expected ID batch or time range' );
112 # Actually update the rows for this job...
113 if ( $uniqueKey !== null ) {
114 # Select the rows to update by PRIMARY KEY
115 $ids = $dbw->selectFieldValues( $table, $uniqueKey, $conds, __METHOD__ );
116 # Update these rows by PRIMARY KEY to avoid replica lag
117 foreach ( array_chunk( $ids, $this->updateRowsPerQuery ) as $batch ) {
118 $dbw->commit( __METHOD__, 'flush' );
119 $this->lbFactory->waitForReplication();
121 $dbw->newUpdateQueryBuilder()
123 ->set( [ $column => $newname ] )
124 ->where( [ $column => $oldname, $uniqueKey => $batch ] )
125 ->caller( __METHOD__ )->execute();
128 # Update the chunk of rows directly
129 $dbw->newUpdateQueryBuilder()
131 ->set( [ $column => $newname ] )
133 ->caller( __METHOD__ )->execute();