X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcreateAndPromote.php;h=c1a2022138c7bcb34ec1717cf1783822df2a3382;hb=83788f5a0e0a885c44fecc43ef9e06191654e808;hp=79f725426d23df768369f31e5c929d19cbbbb3c2;hpb=678dddcce0ac987fe5726c8da820345dd3045b1b;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index 79f725426d..c1a2022138 100644 --- a/maintenance/createAndPromote.php +++ b/maintenance/createAndPromote.php @@ -43,6 +43,14 @@ class CreateAndPromote extends Maintenance { foreach ( self::$permitRoles as $role ) { $this->addOption( $role, "Add the account to the {$role} group" ); } + + $this->addOption( + 'custom-groups', + 'Comma-separated list of groups to add the user to', + false, + true + ); + $this->addArg( "username", "Username of new user" ); $this->addArg( "password", "Password to set (not required if --force is used)", false ); } @@ -69,8 +77,19 @@ class CreateAndPromote extends Maintenance { $inGroups = $user->getGroups(); } + $groups = array_filter( self::$permitRoles, array( $this, 'hasOption' ) ); + if ( $this->hasOption( 'custom-groups' ) ) { + $customGroupsText = $this->getOption( 'custom-groups' ); + if ( $customGroupsText !== '' ) { + $customGroups = explode( ',', $customGroupsText ); + foreach ( $customGroups as $customGroup ) { + $groups[] = trim( $customGroup ); + } + } + } + $promotions = array_diff( - array_filter( self::$permitRoles, array( $this, 'hasOption' ) ), + $groups, $inGroups ); @@ -87,6 +106,12 @@ class CreateAndPromote extends Maintenance { } } + if ( !$exists ) { + # Insert the account into the database + $user->addToDatabase(); + $user->saveSettings(); + } + if ( $password ) { # Try to set the password try { @@ -100,12 +125,6 @@ class CreateAndPromote extends Maintenance { } } - if ( !$exists ) { - # Insert the account into the database - $user->addToDatabase(); - $user->saveSettings(); - } - # Promote user array_map( array( $user, 'addGroup' ), $promotions );