From: Reedy Date: Sun, 29 Jul 2018 02:42:42 +0000 (+0100) Subject: Add a maintenance script to remove all users from a User Group X-Git-Tag: 1.34.0-rc.0~3996 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=ed6d53fd38cbc08ad503174aa09d155dc9867a13 Add a maintenance script to remove all users from a User Group Bug: T185989 Change-Id: Ie5cc95b350230bc730c1f1d9f06fc3e95c5f6bd0 --- diff --git a/autoload.php b/autoload.php index d939089d70..33ee128db0 100644 --- a/autoload.php +++ b/autoload.php @@ -449,6 +449,7 @@ $wgAutoloadLocalClasses = [ 'EmailNotification' => __DIR__ . '/includes/mail/EmailNotification.php', 'EmaillingJob' => __DIR__ . '/includes/jobqueue/jobs/EmaillingJob.php', 'EmptyBagOStuff' => __DIR__ . '/includes/libs/objectcache/EmptyBagOStuff.php', + 'EmptyUserGroup' => __DIR__ . '/maintenance/emptyUserGroup.php', 'EnConverter' => __DIR__ . '/languages/classes/LanguageEn.php', 'EncryptedPassword' => __DIR__ . '/includes/password/EncryptedPassword.php', 'EnhancedChangesList' => __DIR__ . '/includes/changes/EnhancedChangesList.php', diff --git a/maintenance/emptyUserGroup.php b/maintenance/emptyUserGroup.php new file mode 100644 index 0000000000..03a38fcaa1 --- /dev/null +++ b/maintenance/emptyUserGroup.php @@ -0,0 +1,61 @@ +addDescription( 'Remove all users from a given user group' ); + $this->addArg( 'group', 'Group to be removed', true ); + } + + public function execute() { + $group = $this->getArg( 0 ); + + $lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + + $users = User::findUsersByGroup( $group ); + + $count = iterator_count( $users ); + + $this->output( "Removing $count users from $group..." ); + + /** + * @var User $user + */ + foreach ( $users as $user ) { + $user->removeGroup( $group ); + + $lb->waitForReplication(); + } + + $this->output( " Done!\n" ); + } +} + +$maintClass = EmptyUserGroup::class; +require_once RUN_MAINTENANCE_IF_MAIN;