From 99b32dcf2c8f570829db6b63c3213ed76125909f Mon Sep 17 00:00:00 2001 From: Simon Krull Date: Sun, 25 Feb 2024 15:16:53 +0100 Subject: [PATCH] FEATURE: #15888 Introduce sylius:admin-user:delete CLI Command --- .../Command/DeleteAdminUserCommand.php | 68 +++++++++++++++++++ .../AdminBundle/Resources/config/services.xml | 5 ++ 2 files changed, 73 insertions(+) create mode 100644 src/Sylius/Bundle/AdminBundle/Console/Command/DeleteAdminUserCommand.php diff --git a/src/Sylius/Bundle/AdminBundle/Console/Command/DeleteAdminUserCommand.php b/src/Sylius/Bundle/AdminBundle/Console/Command/DeleteAdminUserCommand.php new file mode 100644 index 00000000000..5a2466e2a81 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Console/Command/DeleteAdminUserCommand.php @@ -0,0 +1,68 @@ + $adminUserRepository */ + public function __construct( + private readonly UserRepositoryInterface $adminUserRepository + ) { + parent::__construct(); + } + + protected function initialize(InputInterface $input, OutputInterface $output): void + { + $this->io = new SymfonyStyle($input, $output); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + if (!$input->isInteractive()) { + $this->io->error('This command must be run interactively.'); + return Command::FAILURE; + } + + $this->io->title('Delete admin user'); + + $email = $this->io->ask('Admin E-Mail-Address'); + $adminEmailAddress = $this->adminUserRepository->findOneByEmail($email); + + if ($adminEmailAddress === null) + { + $this->io->error(sprintf('Admin Account with the Email Address "%s" does not exist', $email)); + return Command::INVALID; + } + + $this->adminUserRepository->remove($adminEmailAddress); + + $this->io->success(sprintf('Admin Account with the Email Address "%s" has been deleted successfully', $email)); + + return Command::SUCCESS; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml index b52eeea8181..5406ae79387 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml @@ -49,6 +49,11 @@ + + + + +