46 $oldGroup = $this->
getArg( 0 );
47 $newGroup = $this->
getArg( 1 );
51 $start = $dbw->newSelectQueryBuilder()
52 ->select(
'MIN(ug_user)' )
53 ->from(
'user_groups' )
54 ->where( [
'ug_group' => $oldGroup ] )
55 ->caller( __FUNCTION__ )->fetchField();
56 $end = $dbw->newSelectQueryBuilder()
57 ->select(
'MAX(ug_user)' )
58 ->from(
'user_groups' )
59 ->where( [
'ug_group' => $oldGroup ] )
60 ->caller( __FUNCTION__ )->fetchField();
61 if ( $start ===
null ) {
62 $this->
fatalError(
"Nothing to do - no users in the '$oldGroup' group" );
65 $end += $batchSize - 1;
67 $blockEnd = $start + $batchSize - 1;
69 while ( $blockEnd <= $end ) {
71 $this->
output(
"Doing users $blockStart to $blockEnd\n" );
76 $usersAlreadyInNewGroup = $dbw->newSelectQueryBuilder()
78 ->from(
'user_groups' )
80 'ug_group' => $newGroup,
81 $dbw->expr(
'ug_user',
'>=', (
int)$blockStart ),
82 $dbw->expr(
'ug_user',
'<=', (
int)$blockEnd ),
84 ->caller( __METHOD__ )
88 $updateQueryBuilder = $dbw->newUpdateQueryBuilder()
89 ->update(
'user_groups' )
90 ->set( [
'ug_group' => $newGroup ] )
92 'ug_group' => $oldGroup,
93 $dbw->expr(
'ug_user',
'>=', (
int)$blockStart ),
94 $dbw->expr(
'ug_user',
'<=', (
int)$blockEnd ),
96 ->caller( __METHOD__ );
97 if ( count( $usersAlreadyInNewGroup ) ) {
98 $updateQueryBuilder->where( $dbw->expr(
'ug_user',
'!=', $usersAlreadyInNewGroup ) );
100 $updateQueryBuilder->execute();
101 $affected += $dbw->affectedRows();
105 if ( count( $usersAlreadyInNewGroup ) ) {
106 $dbw->newDeleteQueryBuilder()
107 ->deleteFrom(
'user_groups' )
109 'ug_group' => $oldGroup,
110 $dbw->expr(
'ug_user',
'=', $usersAlreadyInNewGroup ),
112 ->caller( __METHOD__ )->execute();
113 $affected += $dbw->affectedRows();
118 if ( $affected > 0 ) {
121 $res = $dbw->newSelectQueryBuilder()
122 ->select(
'ug_user' )
123 ->from(
'user_groups' )
125 'ug_group' => $newGroup,
126 $dbw->expr(
'ug_user',
'>=', (
int)$blockStart ),
127 $dbw->expr(
'ug_user',
'<=', (
int)$blockEnd ),
129 ->caller( __METHOD__ )->fetchResultSet();
130 if ( $res !==
false ) {
131 foreach ( $res as $row ) {
132 $user = User::newFromId( $row->ug_user );
133 $user->invalidateCache();
134 $userGroupManager->clearCache( $user );
140 $blockStart += $batchSize;
141 $blockEnd += $batchSize;
143 $this->
output(
"Done! $count users in group '$oldGroup' are now in '$newGroup' instead.\n" );