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();
154 $res = $dbw->newSelectQueryBuilder()
155 ->select( array_merge( $primaryKey, [ $idField, $nameField ], $orderby ) )
157 ->where( array_merge( $conds, [ $next ] ) )
158 ->orderBy( $orderby )
159 ->limit( $this->mBatchSize )
160 ->caller( __METHOD__ )
162 if ( !
$res->numRows() ) {
167 foreach (
$res as $row ) {
168 $name = $row->$nameField;
169 if ( $row->$idField || !$userNameUtils->isUsable( $name ) ) {
174 if ( $this->assign ) {
178 if ( !isset( $this->triedCreations[$name] ) ) {
179 $this->triedCreations[$name] =
true;
180 if ( !$this->
getHookRunner()->onImportHandleUnknownUser( $name ) ) {
187 $set = [ $idField => $id ];
188 $counter = &$countAssigned;
190 $set = [ $nameField => substr( $this->prefix .
'>' . $name, 0, 255 ) ];
191 $counter = &$countPrefixed;
197 array_intersect_key( (array)$row, $pkFilter ) + [
203 $counter += $dbw->affectedRows();
207 list( $next, $display ) = $this->makeNextCond( $dbw, $orderby, $row );
208 $this->
output(
"... $display\n" );
209 $lbFactory->waitForReplication();
213 "Completed cleanup, assigned $countAssigned and prefixed $countPrefixed row(s)\n"