mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
bug #10863 [SyliusUserBundle] Improve output of Promote/DemoteUserCommand (markbeazley)
This PR was merged into the 1.5 branch.
Discussion
----------
| Q | A
| --------------- | -----
| Branch? | 1.5
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Related tickets | fixes #10862
| License | MIT
A quick fix to make it clearer to users that if an error happens the user's roles are unchanged. Previously it was showing both success and error messages which gave the impression other role changes that didn't trigger an error had been applied when they hadn't (the entity is only flushed if no errors happen).
<!--
- Bug fixes must be submitted against the 1.4, 1.5 or 1.6 branch (the lowest possible)
- Features and deprecations must be submitted against the master branch
- Make sure that the correct base branch is set
-->
Commits
-------
7350d7c0d3 [SyliusUserBundle] Improve output of PromoteUserCommand and DemoteUserCommand
This commit is contained in:
commit
c5f5fff689
2 changed files with 12 additions and 4 deletions
|
|
@ -49,21 +49,25 @@ EOT
|
|||
protected function executeRoleCommand(InputInterface $input, OutputInterface $output, UserInterface $user, array $securityRoles): void
|
||||
{
|
||||
$error = false;
|
||||
$successMessages = [];
|
||||
|
||||
foreach ($securityRoles as $securityRole) {
|
||||
if (!$user->hasRole($securityRole)) {
|
||||
$output->writeln(sprintf('<error>User "%s" didn\'t have "%s" Security role.</error>', $user->getEmail(), $securityRole));
|
||||
$output->writeln(sprintf('<error>User "%s" doesn\'t have "%s" Security role.</error>', $user->getEmail(), $securityRole));
|
||||
$error = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->removeRole($securityRole);
|
||||
$output->writeln(sprintf('Security role <comment>%s</comment> has been removed from user <comment>%s</comment>', $securityRole, $user->getEmail()));
|
||||
$successMessages[] = sprintf('Security role <comment>%s</comment> has been removed from user <comment>%s</comment>', $securityRole, $user->getEmail());
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$output->writeln($successMessages);
|
||||
$this->getEntityManager($input->getOption('user-type'))->flush();
|
||||
} else {
|
||||
$output->writeln(sprintf('<error>No roles removed from User "%s".</error>', $user->getEmail()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,21 +49,25 @@ EOT
|
|||
protected function executeRoleCommand(InputInterface $input, OutputInterface $output, UserInterface $user, array $securityRoles): void
|
||||
{
|
||||
$error = false;
|
||||
$successMessages = [];
|
||||
|
||||
foreach ($securityRoles as $securityRole) {
|
||||
if ($user->hasRole($securityRole)) {
|
||||
$output->writeln(sprintf('<error>User "%s" did already have "%s" security role.</error>', $user->getEmail(), $securityRole));
|
||||
$output->writeln(sprintf('<error>User "%s" already has "%s" security role.</error>', $user->getEmail(), $securityRole));
|
||||
$error = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->addRole($securityRole);
|
||||
$output->writeln(sprintf('Security role <comment>%s</comment> has been added to user <comment>%s</comment>', $securityRole, $user->getEmail()));
|
||||
$successMessages[] = sprintf('Security role <comment>%s</comment> has been added to user <comment>%s</comment>', $securityRole, $user->getEmail());
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$output->writeln($successMessages);
|
||||
$this->getEntityManager($input->getOption('user-type'))->flush();
|
||||
} else {
|
||||
$output->writeln(sprintf('<error>No roles added to User "%s".</error>', $user->getEmail()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue