From dabb2b4102713fe752cb75874e4be936412b3b75 Mon Sep 17 00:00:00 2001 From: Yann-BUTSCHER-EIRL Date: Sat, 10 Jun 2023 22:17:41 +0200 Subject: [PATCH] Ref #320: remove deprecation linked to commands --- src/Command/CreateAdminAccountCommand.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Command/CreateAdminAccountCommand.php b/src/Command/CreateAdminAccountCommand.php index 1775f3be..6c3cecd1 100644 --- a/src/Command/CreateAdminAccountCommand.php +++ b/src/Command/CreateAdminAccountCommand.php @@ -3,11 +3,17 @@ namespace App\Command; use App\Service\UserService; +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: 'app:create-admin-account', + description: 'Creates an admin account.', +)] class CreateAdminAccountCommand extends Command { /** @@ -15,11 +21,6 @@ class CreateAdminAccountCommand extends Command */ private $userService; - /** - * @var string Name of the command (used in console) - */ - protected static $defaultName = 'app:create-admin-account'; - public function __construct(UserService $userService) { $this->userService = $userService; @@ -45,16 +46,18 @@ protected function configure() * @param InputInterface $input * @param OutputInterface $output */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { - $output->writeln('Admin account creation started...'); + $io = new SymfonyStyle($input, $output); + $io->info('Admin account creation started...'); $this->userService->createFirstAdminAccount( $input->getArgument('admin-username'), $input->getArgument('admin-password') ); - $output->writeln('User successfully generated!'); - } + $io->success('User successfully generated!'); + return Command::SUCCESS; + } }