124 $table, $primaryKey, $idField, $nameField, array $conds, array $orderby
126 if ( $this->table !==
null && $this->table !== $table ) {
131 if ( !$dbw->fieldExists( $table, $idField, __METHOD__ ) ||
132 !$dbw->fieldExists( $table, $nameField, __METHOD__ )
134 $this->
output(
"Skipping $table, fields $idField and/or $nameField do not exist\n" );
138 $primaryKey = (array)$primaryKey;
139 $pkFilter = array_fill_keys( $primaryKey,
true );
140 $this->
output(
"Beginning cleanup of $table\n" );
145 $userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
146 $userIdentityLookup = MediaWikiServices::getInstance()->getUserIdentityLookup();
149 $res = $dbw->newSelectQueryBuilder()
150 ->select( array_merge( $primaryKey, [ $idField, $nameField ], $orderby ) )
152 ->where( array_merge( $conds, [ $next ] ) )
153 ->orderBy( $orderby )
154 ->limit( $this->mBatchSize )
155 ->caller( __METHOD__ )
157 if ( !
$res->numRows() ) {
162 foreach (
$res as $row ) {
163 $name = $row->$nameField;
164 if ( $row->$idField || !$userNameUtils->isUsable( $name ) ) {
169 if ( $this->assign ) {
170 $userIdentity = $userIdentityLookup->getUserIdentityByName( $name );
171 if ( !$userIdentity || !$userIdentity->isRegistered() ) {
173 if ( !isset( $this->triedCreations[$name] ) ) {
174 $this->triedCreations[$name] =
true;
175 if ( !$this->
getHookRunner()->onImportHandleUnknownUser( $name ) ) {
176 $userIdentity = $userIdentityLookup
177 ->getUserIdentityByName( $name, IDBAccessObject::READ_LATEST );
178 $id = $userIdentity ? $userIdentity->getId() : 0;
184 $set = [ $idField => $id ];
185 $counter = &$countAssigned;
187 $set = [ $nameField => substr( $this->prefix .
'>' . $name, 0, 255 ) ];
188 $counter = &$countPrefixed;
194 array_intersect_key( (array)$row, $pkFilter ) + [
200 $counter += $dbw->affectedRows();
204 [ $next, $display ] = $this->makeNextCond( $dbw, $orderby, $row );
205 $this->
output(
"... $display\n" );
210 "Completed cleanup, assigned $countAssigned and prefixed $countPrefixed row(s)\n"