Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3112. #3323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Command/AddUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ class AddUserCommand extends Command
/** @var Config */
private $config;

public function __construct(EntityManagerInterface $em, UserPasswordHasherInterface $passwordHasher, ValidatorInterface $validator, Config $config)
/** @var UserRepository */
private $userRepository;

public function __construct(EntityManagerInterface $em, UserPasswordHasherInterface $passwordHasher, ValidatorInterface $validator, Config $config, UserRepository $userRepository)
{
parent::__construct();

$this->entityManager = $em;
$this->passwordHasher = $passwordHasher;
$this->validator = $validator;
$this->config = $config;
$this->userRepository = $userRepository;
}

/**
Expand Down Expand Up @@ -269,6 +273,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user->setPassword($hashedPassword);
$user->eraseCredentials();

if (null === $this->userRepository->find(1)) {
$firstAdmin = $this->userRepository->getFirstAdminUser();
if (null !== $firstAdmin) {
$firstAdmin->setId(1);
$this->entityManager->persist($firstAdmin);
} else {
$user->setId(1);
}
}

$this->entityManager->persist($user);
$this->entityManager->flush();

Expand Down
9 changes: 7 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public function getId(): int
return $this->id;
}

public function setId(int $id): void
{
$this->id = $id;
}

public function setDisplayName(?string $displayName): void
{
$this->displayName = $displayName;
Expand Down Expand Up @@ -249,7 +254,7 @@ public function serialize(): string
{
return serialize($this->__serialize());
}

public function __serialize(): array
{
return [$this->id, $this->username, $this->password];
Expand All @@ -262,7 +267,7 @@ public function unserialize($serialized): void
{
$this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
}

public function __unserialize(array $data): void
{
// add $this->salt too if you don't use Bcrypt or Argon2i
Expand Down