18require_once __DIR__ .
'/Maintenance.php';
23 parent::__construct();
24 $this->
addDescription(
'Remove all users from a given user group' );
25 $this->
addArg(
'group',
'Group to be removed',
true );
28 'If specified, then log entries are created for each user in the group when emptying the user group.',
32 'If create-log is specified, then this is used as the reason for the log entries created for ' .
33 'emptying the user group. If not provided, then the log will have no reason.',
41 $group = $this->
getArg( 0 );
45 $this->
output(
"Removing users from $group...\n" );
47 $users = User::findUsersByGroup( $group, $this->
getBatchSize() );
48 if ( iterator_count( $users ) === 0 ) {
52 foreach ( $users as $user ) {
53 $oldGroups = $userGroupManager->getUserGroups( $user );
54 $groupRemoved = $userGroupManager->removeUserFromGroup( $user, $group );
56 if ( $groupRemoved ) {
59 $this->createLogEntry( $user, $group, $oldGroups );
67 $this->
output(
" ...done! Removed $totalCount users in total.\n" );
69 $this->
output(
" ...nothing to do, group was empty.\n" );
83 private function createLogEntry(
UserIdentity $target,
string $removedGroup, array $oldGroups ) {
84 $newGroups = $oldGroups;
85 $newGroups = array_diff( $newGroups, [ $removedGroup ] );
88 $logEntry->setPerformer( User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] ) );
89 $logEntry->setTarget( Title::makeTitle(
NS_USER, $target->
getName() ) );
90 $logEntry->setComment( $this->
getOption(
'log-reason',
'' ) );
91 $logEntry->setParameters( [
92 '4::oldgroups' => $oldGroups,
93 '5::newgroups' => $newGroups,
101require_once RUN_MAINTENANCE_IF_MAIN;
execute()
Do the actual work.
__construct()
Default constructor.
Class for creating new log entries and inserting them into the database.
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.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.