104 for ( $i = count( $indexFields ) - 1; $i >= 0; $i-- ) {
105 $field = $indexFields[$i];
106 $display[] = $field .
'=' . $row->$field;
107 $value = $dbw->addQuotes( $row->$field );
108 if ( $next ===
'' ) {
109 $next =
"$field > $value";
111 $next =
"$field > $value OR $field = $value AND ($next)";
114 $display = implode(
' ', array_reverse( $display ) );
115 return [ $next, $display ];
129 $table, $primaryKey, $idField, $nameField, array $conds, array $orderby
131 if ( $this->table !==
null && $this->table !==
$table ) {
136 if ( !$dbw->fieldExists(
$table, $idField, __METHOD__ ) ||
137 !$dbw->fieldExists(
$table, $nameField, __METHOD__ )
139 $this->
output(
"Skipping $table, fields $idField and/or $nameField do not exist\n" );
143 $primaryKey = (array)$primaryKey;
144 $pkFilter = array_fill_keys( $primaryKey,
true );
145 $this->
output(
"Beginning cleanup of $table\n" );
150 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
151 $userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
156 array_merge( $primaryKey, [ $idField, $nameField ], $orderby ),
157 array_merge( $conds, [ $next ] ),
160 'ORDER BY' => $orderby,
161 'LIMIT' => $this->mBatchSize,
164 if ( !
$res->numRows() ) {
169 foreach (
$res as $row ) {
170 $name = $row->$nameField;
171 if ( $row->$idField || !$userNameUtils->isUsable( $name ) ) {
176 if ( $this->assign ) {
180 if ( !isset( $this->triedCreations[$name] ) ) {
181 $this->triedCreations[$name] =
true;
182 if ( !$this->
getHookRunner()->onImportHandleUnknownUser( $name ) ) {
189 $set = [ $idField => $id ];
190 $counter = &$countAssigned;
192 $set = [ $nameField => substr( $this->prefix .
'>' . $name, 0, 255 ) ];
193 $counter = &$countPrefixed;
199 array_intersect_key( (array)$row, $pkFilter ) + [
205 $counter += $dbw->affectedRows();
208 list( $next, $display ) = $this->
makeNextCond( $dbw, $orderby, $row );
209 $this->
output(
"... $display\n" );
210 $lbFactory->waitForReplication();
214 "Completed cleanup, assigned $countAssigned and prefixed $countPrefixed row(s)\n"