Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 5eb225a3 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

delete lexicon command interactive

parent f68423d7
...@@ -2,25 +2,25 @@ ...@@ -2,25 +2,25 @@
namespace LexiconBundle\Command; namespace LexiconBundle\Command;
use LexiconBundle\Manager\ImportManager;
use LexiconBundle\Entity\Language; use LexiconBundle\Entity\Language;
use LexiconBundle\Entity\Root; use LexiconBundle\Entity\Root;
use LexiconBundle\Entity\Word; use LexiconBundle\Entity\Word;
use LexiconBundle\Entity\WordStart; use LexiconBundle\Entity\WordStart;
use MagicWordBundle\Entity\Grid; use LexiconBundle\Manager\ImportManager;
use MagicWordBundle\Entity\FoundableForm;
use MagicWordBundle\Entity\Game; use MagicWordBundle\Entity\Game;
use MagicWordBundle\Entity\Grid;
use MagicWordBundle\Entity\Objective;
use MagicWordBundle\Entity\Round; use MagicWordBundle\Entity\Round;
use MagicWordBundle\Entity\Score; use MagicWordBundle\Entity\Score;
use MagicWordBundle\Entity\Wordbox\Acquisition; use MagicWordBundle\Entity\Wordbox\Acquisition;
use MagicWordBundle\Entity\WrongForm; use MagicWordBundle\Entity\WrongForm;
use MagicWordBundle\Entity\FoundableForm; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use MagicWordBundle\Entity\Objective;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Question\Question;
use Symfony\Component\Filesystem\Filesystem;
class DeleteLexiconCommand extends ContainerAwareCommand class DeleteLexiconCommand extends ContainerAwareCommand
{ {
...@@ -28,23 +28,29 @@ class DeleteLexiconCommand extends ContainerAwareCommand ...@@ -28,23 +28,29 @@ class DeleteLexiconCommand extends ContainerAwareCommand
{ {
$this $this
->setName('lexicon:delete') ->setName('lexicon:delete')
->setDescription('Delete lexicon from db & bigram.txt files') ->setDescription('Delete lexicon from db & bigram.txt files');
->addArgument('id_lexicon', InputArgument::REQUIRED, 'id of lexicon you want to delete');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$em = $this->getContainer()->get('doctrine')->getEntityManager('default'); $em = $this->getContainer()->get('doctrine')->getEntityManager('default');
$idLexicon = $input->getArgument('id_lexicon'); $helper = $this->getHelper('question');
$question = new Question("Please enter the ID of the lexicon \n");
$languages = $em->getRepository(Language::class)->findAll();
foreach ($languages as $language) {
$output->writeln('<comment>'.$language->getId()." > ".$language->getValue().'</comment>');
}
$idLexicon = $helper->ask($input, $output, $question);
if ($idLexicon) { if ($idLexicon) {
$language = $em->getRepository(Language::class)->find($idLexicon); $language = $em->getRepository(Language::class)->find($idLexicon);
if ($language) { if ($language) {
$output->writeln('<info>############ SUPPRESSION LANGUE #############</info>'); $output->writeln('<info>############ SUPPRESSION LANGUE #############</info>');
echo "Suppression ".$language->getValue(); echo "Suppression ".$language->getValue()."\n";
$output->writeln('<comment>Suppression acquisitions</comment>');
$em->getRepository(Acquisition::class)->deleteByLanguage($language); $em->getRepository(Acquisition::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression acquisitions</comment>'); $output->writeln('<comment>Suppression acquisitions</comment>');
...@@ -68,7 +74,6 @@ class DeleteLexiconCommand extends ContainerAwareCommand ...@@ -68,7 +74,6 @@ class DeleteLexiconCommand extends ContainerAwareCommand
$em->getRepository(Game::class)->deleteByLanguage($language); $em->getRepository(Game::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression game ok</comment>'); $output->writeln('<comment>Suppression game ok</comment>');
// delete grid // delete grid
$rounds = $em->getRepository(Round::class)->findByLanguage($language); $rounds = $em->getRepository(Round::class)->findByLanguage($language);
foreach ($rounds as $round) { foreach ($rounds as $round) {
...@@ -119,10 +124,6 @@ class DeleteLexiconCommand extends ContainerAwareCommand ...@@ -119,10 +124,6 @@ class DeleteLexiconCommand extends ContainerAwareCommand
$output->writeln('<info>########### SUPPRESSION LANGUE OK ############</info>'); $output->writeln('<info>########### SUPPRESSION LANGUE OK ############</info>');
} else { } else {
$output->writeln('<comment>Pas de langue avec cet ID</comment>'); $output->writeln('<comment>Pas de langue avec cet ID</comment>');
$languages = $em->getRepository(Language::class)->findAll();
foreach ($languages as $language) {
$output->writeln('<comment>'.$language->getId()." > ".$language->getValue().'</comment>');
}
} }
} else { } else {
echo 'Argument missing (language id)'; echo 'Argument missing (language id)';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment