X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=blobdiff_plain;f=maintenance%2FcreateAndPromote.php;h=8bff284a1171617d1b820856fe6960f64bff9ac5;hb=31851e18cfe03cce03a8c9bd6a62b79abb1b4c81;hp=7ef48e08c934cf3fafc4e95e569af9bbde7dd0d0;hpb=c771fc9c96aacb44b86ade5ecca68334c5d8213f;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index 7ef48e08c9..8bff284a11 100644 --- a/maintenance/createAndPromote.php +++ b/maintenance/createAndPromote.php @@ -1,46 +1,75 @@ */ - -require_once( 'commandLine.inc' ); -if( !count( $args ) == 2 ) { - echo( "Please provide a username and password for the new account.\n" ); - die( 1 ); -} +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); -$username = $args[0]; -$password = $args[1]; +class CreateAndPromote extends Maintenance { -echo( wfWikiID() . ": Creating and promoting User:{$username}..." ); + public function __construct() { + parent::__construct(); + $this->mDescription = "Create a new user account with administrator rights"; + $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" ); + $this->addArg( "username", "Username of new user" ); + $this->addArg( "password", "Password to set" ); + } -# Validate username and check it doesn't exist -$user = User::newFromName( $username ); -if( !is_object( $user ) ) { - echo( "invalid username.\n" ); - die( 1 ); -} elseif( 0 != $user->idForName() ) { - echo( "account exists.\n" ); - die( 1 ); -} + public function execute() { + $username = $this->getArg( 0 ); + $password = $this->getArg( 1 ); + + $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." ); + + $user = User::newFromName( $username ); + if ( !is_object( $user ) ) { + $this->error( "invalid username.", true ); + } elseif ( 0 != $user->idForName() ) { + $this->error( "account exists.", true ); + } -# Insert the account into the database -$user->addToDatabase(); -$user->setPassword( $password ); -$user->setToken(); + # Try to set the password + try { + $user->setPassword( $password ); + } catch ( PasswordError $pwe ) { + $this->error( $pwe->getText(), true ); + } -# Promote user -$user->addGroup( 'sysop' ); + # Insert the account into the database + $user->addToDatabase(); + $user->saveSettings(); -# Increment site_stats.ss_users -$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); -$ssu->doUpdate(); + # Promote user + $user->addGroup( 'sysop' ); + if ( $this->hasOption( 'bureaucrat' ) ) + $user->addGroup( 'bureaucrat' ); -echo( "done.\n" ); + # Increment site_stats.ss_users + $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); + $ssu->doUpdate(); + + $this->output( "done.\n" ); + } +} -?> +$maintClass = "CreateAndPromote"; +require_once( RUN_MAINTENANCE_IF_MAIN ); \ No newline at end of file