32require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Remove all users from a given user group' );
39 $this->
addArg(
'group',
'Group to be removed',
true );
42 'If specified, then log entries are created for each user in the group when emptying the user group.',
46 'If create-log is specified, then this is used as the reason for the log entries created for ' .
47 'emptying the user group. If not provided, then the log will have no reason.',
55 $group = $this->
getArg( 0 );
59 $this->
output(
"Removing users from $group...\n" );
61 $users = User::findUsersByGroup( $group, $this->
getBatchSize() );
62 if ( iterator_count( $users ) === 0 ) {
66 foreach ( $users as $user ) {
67 $oldGroups = $userGroupManager->getUserGroups( $user );
68 $groupRemoved = $userGroupManager->removeUserFromGroup( $user, $group );
70 if ( $groupRemoved ) {
73 $this->createLogEntry( $user, $group, $oldGroups );
81 $this->
output(
" ...done! Removed $totalCount users in total.\n" );
83 $this->
output(
" ...nothing to do, group was empty.\n" );
97 private function createLogEntry(
UserIdentity $target,
string $removedGroup, array $oldGroups ) {
98 $newGroups = $oldGroups;
99 $newGroups = array_diff( $newGroups, [ $removedGroup ] );
102 $logEntry->setPerformer( User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] ) );
103 $logEntry->setTarget( Title::makeTitle(
NS_USER, $target->
getName() ) );
104 $logEntry->setComment( $this->
getOption(
'log-reason',
'' ) );
105 $logEntry->setParameters( [
106 '4::oldgroups' => $oldGroups,
107 '5::newgroups' => $newGroups,
115require_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.