MediaWiki master
emptyUserGroup.php
Go to the documentation of this file.
1<?php
2
26
27// @codeCoverageIgnoreStart
28require_once __DIR__ . '/Maintenance.php';
29// @codeCoverageIgnoreEnd
30
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// @codeCoverageIgnoreStart
65$maintClass = EmptyUserGroup::class;
66require_once RUN_MAINTENANCE_IF_MAIN;
67// @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.
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