Skip to content
Snippets Groups Projects
Commit 3170a092 authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Commande update lexiques utilisateurs

parent f6163088
No related branches found
No related tags found
No related merge requests found
<?php
namespace App\Command\Temp;
use App\Entity\Label;
use App\Entity\Lexicon;
use App\Entity\User;
use App\Languages\LanguagesIso;
use Doctrine\ORM\EntityManagerInterface;
use League\Bundle\OAuth2ServerBundle\Model\Client;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
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\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Uid\UuidV1;
class UpdateLexiconsCommand extends Command
{
protected static $defaultName = "app:lexicon:update";
protected static $defaultDescription = "Création si nécessaire d'un lexique par langue étudiée pour chaque utilisateur.";
/**
* @var EntityManagerInterface
*/
private $em;
public function __construct(EntityManagerInterface $em)
{
parent::__construct();
$this->em = $em;
}
// protected function configure(): void
// {
// $this
// ->addOption('email', null, InputOption::VALUE_REQUIRED, 'User email adddress', 'me@davegebler.com')
// ->addOption('password', null, InputOption::VALUE_REQUIRED, 'User password', 'password')
// ->addOption('redirect-uris', null, InputOption::VALUE_REQUIRED, 'Redirect URIs', 'http://localhost:8001/callback')
// ;
// }
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$users = $this->em->getRepository(User::class)->findAll();
foreach ($users as $user) {
foreach ($user->getStudiedLanguages() as $studiedLanguage) {
if (!$user->hasPersonalLexiconForLanguage($studiedLanguage->getLanguage())) {
$lexicon = new Lexicon();
$lexicon->setUser($user);
$lexicon->setLanguage($studiedLanguage->getLanguage());
$lexicon->setCategory(Lexicon::TYPE_USER);
$user->addLexicon($lexicon);
$io->writeln(sprintf("lexique %s créé pour %s", $lexicon->getLanguage(), $user));
}
}
}
$this->em->flush();
$io->success('Succès initialisation.');
return Command::SUCCESS;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment