svg
This commit is contained in:
@ -7,13 +7,10 @@ use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
#[AsCommand(
|
||||
@ -26,7 +23,7 @@ class InitCommand extends Command
|
||||
private ParameterBagInterface $params;
|
||||
private UserPasswordHasherInterface $passwordHasher;
|
||||
|
||||
public function __construct(EntityManagerInterface $em,ParameterBagInterface $params,UserPasswordHasherInterface $passwordHasher)
|
||||
public function __construct(EntityManagerInterface $em, ParameterBagInterface $params, UserPasswordHasherInterface $passwordHasher)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->params = $params;
|
||||
@ -38,38 +35,41 @@ class InitCommand extends Command
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title("APP:INIT");
|
||||
$io->text("Initialisation of the app");
|
||||
$io->text("");
|
||||
|
||||
$io->title('APP:INIT');
|
||||
$io->text('Initialisation of the app');
|
||||
$io->text('');
|
||||
|
||||
// Création du compte admin
|
||||
$io->text("> Création du compte admin");
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(["username"=>"admin"]);
|
||||
if(!$user) {
|
||||
$user=new User;
|
||||
$io->text('> Création du compte admin');
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(['username' => 'admin']);
|
||||
if (!$user) {
|
||||
$user = new User();
|
||||
|
||||
$hashedPassword = $this->passwordHasher->hashPassword(
|
||||
$user,
|
||||
$this->params->get("appSecret")
|
||||
$this->params->get('appSecret')
|
||||
);
|
||||
|
||||
$user->setUsername("admin");
|
||||
$user->setUsername('admin');
|
||||
$user->setPassword($hashedPassword);
|
||||
$user->setAvatar('medias/avatar/admin.jpg');
|
||||
$user->setEmail($this->params->get('appNoreply'));
|
||||
$this->em->persist($user);
|
||||
}
|
||||
$user->setRoles(["ROLE_ADMIN"]);
|
||||
$user->setRoles(['ROLE_ADMIN']);
|
||||
$this->em->flush();
|
||||
|
||||
// Création d'un company par defaut
|
||||
$io->text("> Création d'un company par defaut");
|
||||
$nbcompanys = $this->em->getRepository("App\Entity\Company")->count([]);
|
||||
if($nbcompanys==0) {
|
||||
$company=new Company;
|
||||
$company->setTitle($this->params->get("appName"));
|
||||
$company->setLogo("logo.png");
|
||||
if (0 == $nbcompanys) {
|
||||
$company = new Company();
|
||||
$company->setTitle($this->params->get('appName'));
|
||||
$company->setLogo('logo.png');
|
||||
$this->em->persist($company);
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user