-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57859f5
commit 6babc7e
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace RockShell; | ||
|
||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class UserRename extends Command | ||
{ | ||
|
||
public function config() | ||
{ | ||
$this | ||
->setDescription("Rename a user") | ||
->addOption("user", "u", InputOption::VALUE_OPTIONAL, "name of existing user") | ||
->addOption("name", "r", InputOption::VALUE_OPTIONAL, "new username"); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$users = []; | ||
foreach ($this->wire()->users as $u) $users[] = $u->name; | ||
|
||
if (!$user = $this->option('user')) { | ||
$user = $this->choice("Select user", $users); | ||
} | ||
|
||
$name = $this->option('name'); | ||
$name = $this->wire()->sanitizer->pageName($name); | ||
while (!$name or in_array($name, $users)) { | ||
$name = $this->ask("Enter new username"); | ||
$name = $this->wire()->sanitizer->pageName($name); | ||
} | ||
|
||
$user = $this->wire()->users->get("name=$user"); | ||
$this->success("User {$user->name} renamed to $name"); | ||
$user->setAndSave('name', $name); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |