MediaWiki master
emptyUserGroup.php
Go to the documentation of this file.
1<?php
2
26
27require_once __DIR__ . '/Maintenance.php';
28
30 public function __construct() {
31 parent::__construct();
32 $this->addDescription( 'Remove all users from a given user group' );
33 $this->addArg( 'group', 'Group to be removed', true );
34 $this->setBatchSize( 100 );
35 }
36
37 public function execute() {
38 $group = $this->getArg( 0 );
39 $userGroupManager = $this->getServiceContainer()->getUserGroupManager();
40
41 $totalCount = 0;
42 $this->output( "Removing users from $group...\n" );
43 while ( true ) {
44 $users = User::findUsersByGroup( $group, $this->getBatchSize() );
45 if ( iterator_count( $users ) === 0 ) {
46 break;
47 }
48
49 foreach ( $users as $user ) {
50 $totalCount += (int)$userGroupManager->removeUserFromGroup( $user, $group );
51 }
52 $this->waitForReplication();
53 }
54 if ( $totalCount ) {
55 $this->output( " ...done! Removed $totalCount users in total.\n" );
56 } else {
57 $this->output( " ...nothing to do, group was empty.\n" );
58 }
59 }
60}
61
62$maintClass = EmptyUserGroup::class;
63require_once RUN_MAINTENANCE_IF_MAIN;
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
getServiceContainer()
Returns the main service container.
getBatchSize()
Returns batch size.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
internal since 1.36
Definition User.php:93
$maintClass