MediaWiki  master
emptyUserGroup.php
Go to the documentation of this file.
1 <?php
2 
25 require_once __DIR__ . '/Maintenance.php';
26 
28 
29 class EmptyUserGroup extends Maintenance {
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  }
35 
36  public function execute() {
37  $group = $this->getArg( 0 );
38 
39  $lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
40 
41  $users = User::findUsersByGroup( $group );
42 
43  $count = iterator_count( $users );
44 
45  $this->output( "Removing $count users from $group..." );
46 
50  foreach ( $users as $user ) {
51  $user->removeGroup( $group );
52 
53  $lb->waitForReplication();
54  }
55 
56  $this->output( " Done!\n" );
57  }
58 }
59 
60 $maintClass = EmptyUserGroup::class;
61 require_once RUN_MAINTENANCE_IF_MAIN;
getArg( $argId=0, $default=null)
Get an argument.
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:86
static findUsersByGroup( $groups, $limit=5000, $after=null)
Return the users who are members of the given group(s).
Definition: User.php:1001
addDescription( $text)
Set the description text.
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
$maintClass