diff --git a/src/Command/Temp/UpdateLexiconsCommand.php b/src/Command/Temp/UpdateLexiconsCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..9026b5c3b904a34de31309441f3c9ba68c1b05bc --- /dev/null +++ b/src/Command/Temp/UpdateLexiconsCommand.php @@ -0,0 +1,73 @@ +<?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; + } +}