forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: [AdminBundle] Sylius#15890 Introduce sylius:admin-user:list …
…command
- Loading branch information
1 parent
e203a51
commit 3c7890d
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/Sylius/Bundle/AdminBundle/Console/Command/ListAdminUsersCommand.php
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,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\AdminBundle\Console\Command; | ||
|
||
use Sylius\Component\Core\Model\AdminUser; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Sylius\Component\Core\Model\AdminUserInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Sylius\Component\User\Repository\UserRepositoryInterface; | ||
|
||
#[AsCommand( | ||
name: 'sylius:admin-users:list', | ||
description: 'List all admin users', | ||
)] | ||
final class ListAdminUsersCommand extends Command | ||
{ | ||
protected SymfonyStyle $io; | ||
|
||
/** @param UserRepositoryInterface<AdminUserInterface> $userRepositoryInterface */ | ||
public function __construct( | ||
private readonly UserRepositoryInterface $userRepositoryInterface | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function initialize(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$this->io = new SymfonyStyle($input, $output); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->io->title('List available admin users'); | ||
|
||
$adminUsers = $this->userRepositoryInterface->findAll(); | ||
/** @var AdminUser $adminUser */ | ||
foreach ($adminUsers as $adminUser) { | ||
$this->io->table( | ||
[ | ||
'ID', 'E-Mail', 'Username', 'First name', 'Last name', 'Locale code', 'Enabled', | ||
], | ||
[ | ||
[ | ||
$adminUser->getId(), | ||
$adminUser->getEmail(), | ||
$adminUser->getUsername(), | ||
$adminUser->getFirstname() ?? 'No Firstname Set', | ||
$adminUser->getLastName() ?? 'No Lastname Set', | ||
$adminUser->getLocaleCode(), | ||
$adminUser->isEnabled() ? 'Enabled' : 'Disabled', | ||
], | ||
], | ||
); | ||
} | ||
return Command::SUCCESS; | ||
} | ||
} |
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