71 $this->initServices();
76 if ( $this->
getOption(
'performer' ) ===
null ) {
77 $performer = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
82 $this->
fatalError(
"Unable to get performer account" );
84 $this->performer = $performer;
86 $this->reason = $this->
getOption(
'reason',
'' );
87 $this->dryRun = $this->
getOption(
'dry-run' );
88 $this->suppressRedirect = $this->
getOption(
'suppress-redirect' );
89 $this->skipPageMoves = $this->
getOption(
'skip-page-moves' );
96 $res = $dbr->newSelectQueryBuilder()
97 ->select( [
'user_name' ] )
99 ->where( $dbr->expr(
'user_name', IExpression::LIKE, $fromPattern->toLikeValue( $dbr ) ) )
100 ->andWhere( $batchConds )
101 ->orderBy(
'user_name' )
102 ->limit( $batchSize )
103 ->caller( __METHOD__ )
106 foreach ( $res as $row ) {
107 $oldName = $row->user_name;
108 $batchConds = [ $dbr->expr(
'user_name',
'>', $oldName ) ];
109 $variablePart = $fromPattern->extract( $oldName );
110 if ( $variablePart ===
null ) {
111 $this->
output(
"Username \"fromName\" matched the LIKE " .
112 "but does not seem to match the pattern" );
115 $newName = $toPattern->generate( $variablePart );
118 $newTitle = $this->titleFactory->makeTitleSafe(
NS_USER, $newName );
119 $newUser = $this->userFactory->newFromName( $newName );
120 if ( !$newTitle || !$newUser ) {
121 $this->
output(
"Cannot rename \"$oldName\" " .
122 "because \"$newName\" is not a valid title\n" );
125 $newName = $newTitle->getText();
128 if ( $newUser->isRegistered() ) {
129 $this->
output(
"Cannot rename \"$oldName\" " .
130 "because \"$newName\" already exists\n" );
134 $numRenamed += $this->renameUser( $oldName, $newName ) ? 1 : 0;
137 }
while ( $res->numRows() === $batchSize );
138 $this->
output(
"Renamed $numRenamed user(s)\n" );
163 $rename = $this->renameUserFactory->newRenameUser( $this->performer, $oldUser, $newName, $this->reason, [