| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
use MediaWiki\User\User; |
| 26 |
|
| 27 |
|
| 28 |
require_once __DIR__ . '/Maintenance.php'; |
| 29 |
|
| 30 |
|
| 31 |
class EmptyUserGroup extends Maintenance { |
| 32 |
public function __construct() { |
| 33 |
parent::__construct(); |
| 34 |
$this->addDescription( 'Remove all users from a given user group' ); |
| 35 |
$this->addArg( 'group', 'Group to be removed', true ); |
| 36 |
$this->setBatchSize( 100 ); |
| 37 |
} |
| 38 |
|
| 39 |
public function execute() { |
| 40 |
$group = $this->getArg( 0 ); |
| 41 |
$userGroupManager = $this->getServiceContainer()->getUserGroupManager(); |
| 42 |
|
| 43 |
$totalCount = 0; |
| 44 |
$this->output( "Removing users from $group...\n" ); |
| 45 |
while ( true ) { |
| 46 |
$users = User::findUsersByGroup( $group, $this->getBatchSize() ); |
| 47 |
if ( iterator_count( $users ) === 0 ) { |
| 48 |
break; |
| 49 |
} |
| 50 |
|
| 51 |
foreach ( $users as $user ) { |
| 52 |
$totalCount += (int)$userGroupManager->removeUserFromGroup( $user, $group ); |
| 53 |
} |
| 54 |
$this->waitForReplication(); |
| 55 |
} |
| 56 |
if ( $totalCount ) { |
| 57 |
$this->output( " ...done! Removed $totalCount users in total.\n" ); |
| 58 |
} else { |
| 59 |
$this->output( " ...nothing to do, group was empty.\n" ); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
$maintClass = EmptyUserGroup::class; |
| 66 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 67 |
|