MediaWiki master
emptyUserGroup.php
Go to the documentation of this file.
1<?php
2
27
28// @codeCoverageIgnoreStart
29require_once __DIR__ . '/Maintenance.php';
30// @codeCoverageIgnoreEnd
31
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Remove all users from a given user group' );
36 $this->addArg( 'group', 'Group to be removed', true );
37 $this->setBatchSize( 100 );
38 }
39
40 public function execute() {
41 $group = $this->getArg( 0 );
42 $userGroupManager = $this->getServiceContainer()->getUserGroupManager();
43
44 $totalCount = 0;
45 $this->output( "Removing users from $group...\n" );
46 while ( true ) {
47 $users = User::findUsersByGroup( $group, $this->getBatchSize() );
48 if ( iterator_count( $users ) === 0 ) {
49 break;
50 }
51
52 foreach ( $users as $user ) {
53 $totalCount += (int)$userGroupManager->removeUserFromGroup( $user, $group );
54 }
55 $this->waitForReplication();
56 }
57 if ( $totalCount ) {
58 $this->output( " ...done! Removed $totalCount users in total.\n" );
59 } else {
60 $this->output( " ...nothing to do, group was empty.\n" );
61 }
62 }
63}
64
65// @codeCoverageIgnoreStart
66$maintClass = EmptyUserGroup::class;
67require_once RUN_MAINTENANCE_IF_MAIN;
68// @codeCoverageIgnoreEnd
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.
getArg( $argId=0, $default=null)
Get an argument.
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DB servers to catch up.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
User class for the MediaWiki software.
Definition User.php:119
$maintClass