Don't allow createAndPromote.php to add users to invalid groups
authorReedy <reedy@wikimedia.org>
Sun, 3 Apr 2016 11:28:48 +0000 (12:28 +0100)
committerReedy <reedy@wikimedia.org>
Sun, 3 Apr 2016 11:28:48 +0000 (12:28 +0100)
Bug: T131704
Change-Id: Ibe8839e62af8db002adea68ffa87b3adf2b505ea

maintenance/createAndPromote.php

index 9abc297..848c2f7 100644 (file)
@@ -79,11 +79,16 @@ class CreateAndPromote extends Maintenance {
 
                $groups = array_filter( self::$permitRoles, [ $this, 'hasOption' ] );
                if ( $this->hasOption( 'custom-groups' ) ) {
+                       $allGroups = array_flip( User::getAllGroups() );
                        $customGroupsText = $this->getOption( 'custom-groups' );
                        if ( $customGroupsText !== '' ) {
                                $customGroups = explode( ',', $customGroupsText );
                                foreach ( $customGroups as $customGroup ) {
-                                       $groups[] = trim( $customGroup );
+                                       if ( isset( $allGroups[$customGroup] ) ) {
+                                               $groups[] = trim( $customGroup );
+                                       } else {
+                                               $this->output( "$customGroup is not a valid group, ignoring!\n" );
+                                       }
                                }
                        }
                }