Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -11,32 +11,27 @@ namespace App\Command;
use App\Entity\User;
use App\User\UserService;
use App\Utils\CommandStyle;
use App\Validator\ValidationFailedException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(name: 'kimai:user:create')]
final class CreateUserCommand extends AbstractUserCommand
{
private $userService;
public function __construct(UserService $userService)
public function __construct(private UserService $userService)
{
parent::__construct();
$this->userService = $userService;
}
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$roles = implode(',', [User::DEFAULT_ROLE, User::ROLE_ADMIN]);
$this
->setName('kimai:user:create')
->setAliases(['kimai:create-user'])
->setDescription('Create a new user')
->setHelp('This command allows you to create a new user.')
->addArgument('username', InputArgument::REQUIRED, 'A name for the new user (must be unique)')
@@ -51,12 +46,9 @@ final class CreateUserCommand extends AbstractUserCommand
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new CommandStyle($input, $output);
$io = new SymfonyStyle($input, $output);
$username = $input->getArgument('username');
$email = $input->getArgument('email');
@@ -71,7 +63,7 @@ final class CreateUserCommand extends AbstractUserCommand
$role = $role ?: User::DEFAULT_ROLE;
$user = $this->userService->createNewUser();
$user->setUsername($username);
$user->setUserIdentifier($username);
$user->setPlainPassword($password);
$user->setEmail($email);
$user->setEnabled(true);
@@ -81,11 +73,11 @@ final class CreateUserCommand extends AbstractUserCommand
$this->userService->saveNewUser($user);
$io->success(sprintf('Success! Created user: %s', $username));
} catch (ValidationFailedException $ex) {
$io->validationError($ex);
$this->validationError($ex, $io);
return 2;
return Command::FAILURE;
}
return 0;
return Command::SUCCESS;
}
}