Skip to content

Commit

Permalink
cr remarks vol1
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Aug 27, 2024
1 parent fc94767 commit eb29b44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ parameters:
count: 1
path: src/bundle/Command/AuditUserDatabaseCommand.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/bundle/Command/UpdateUserCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\User\\\\Controller\\\\Controller\\:\\:performAccessCheck\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
40 changes: 28 additions & 12 deletions src/bundle/Command/UpdateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ final class UpdateUserCommand extends Command
public function __construct(
private readonly UserService $userService,
private readonly Repository $repository,
?string $name = null
) {
parent::__construct($name);
parent::__construct();
}

protected function configure(): void
Expand All @@ -42,7 +41,7 @@ protected function configure(): void
'password',
null,
InputOption::VALUE_NONE,
'New plaintext password (input will be in a "hidden" mode)',
'New plaintext password (input will be in a "hidden" mode)'
);
$this->addOption(
'email',
Expand All @@ -64,6 +63,19 @@ protected function configure(): void
);
}

protected function interact(InputInterface $input, OutputInterface $output): void
{
$io = new SymfonyStyle($input, $output);
$password = $input->getOption('password');

if (!$password) {
return;
}

$password = $io->askHidden('Password (your input will be hidden)');
$input->setOption('password', $password);
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
Expand All @@ -79,9 +91,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$email = $input->getOption('email');

if (!$password && !$enable && !$disable && $email === null) {
$io->success('No new user data specified, exiting.');
$io->error('No new user data specified, exiting.');

return Command::SUCCESS;
return Command::FAILURE;
}

$user = $this->userService->loadUserByLogin($userReference);
Expand All @@ -92,15 +104,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

if ($password) {
$password = $io->askHidden('Password (your input will be hidden)');
$input->setOption('password', $password);
}

$userUpdateStruct = new UserUpdateStruct();
$userUpdateStruct->password = $input->getOption('password');
$userUpdateStruct->password = null;
$userUpdateStruct->email = $email;
$userUpdateStruct->enabled = $enable === true || !$disable;
$userUpdateStruct->enabled = $this->resolveEnabledFlag($enable, $disable);

$this->repository->sudo(
function () use ($user, $userUpdateStruct): User {
Expand All @@ -112,4 +119,13 @@ function () use ($user, $userUpdateStruct): User {

return Command::SUCCESS;
}

private function resolveEnabledFlag(bool $enable, bool $disable): ?bool
{
if (!$enable && !$disable) {
return null;
}

return $enable === true || !$disable;
}
}

0 comments on commit eb29b44

Please sign in to comment.