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 f68423d7 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

delete command

parent 30676f54
...@@ -11,6 +11,7 @@ use MagicWordBundle\Entity\Grid; ...@@ -11,6 +11,7 @@ use MagicWordBundle\Entity\Grid;
use MagicWordBundle\Entity\Game; use MagicWordBundle\Entity\Game;
use MagicWordBundle\Entity\Round; use MagicWordBundle\Entity\Round;
use MagicWordBundle\Entity\Score; use MagicWordBundle\Entity\Score;
use MagicWordBundle\Entity\Wordbox\Acquisition;
use MagicWordBundle\Entity\WrongForm; use MagicWordBundle\Entity\WrongForm;
use MagicWordBundle\Entity\FoundableForm; use MagicWordBundle\Entity\FoundableForm;
use MagicWordBundle\Entity\Objective; use MagicWordBundle\Entity\Objective;
...@@ -33,84 +34,98 @@ class DeleteLexiconCommand extends ContainerAwareCommand ...@@ -33,84 +34,98 @@ class DeleteLexiconCommand extends ContainerAwareCommand
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$output->writeln('<info>############ SUPPRESSION LANGUE #############</info>');
$em = $this->getContainer()->get('doctrine')->getEntityManager('default'); $em = $this->getContainer()->get('doctrine')->getEntityManager('default');
$idLexicon = $input->getArgument('id_lexicon'); $idLexicon = $input->getArgument('id_lexicon');
if ($idLexicon) { if ($idLexicon) {
$language = $em->getRepository(Language::class)->find($idLexicon); $language = $em->getRepository(Language::class)->find($idLexicon);
echo 'You passed an argument: ' . $idLexicon . "\n\n"; if ($language) {
$output->writeln('<info>############ SUPPRESSION LANGUE #############</info>');
$games = $em->getRepository(Game::class)->findByLanguage($language);
foreach ($games as $game) { echo "Suppression ".$language->getValue();
$scores = $em->getRepository(Score::class)->findByGame($game); $output->writeln('<comment>Suppression acquisitions</comment>');
foreach ($scores as $score) {
$em->remove($score);
foreach ($score->getActivities() as $activity) { $em->getRepository(Acquisition::class)->deleteByLanguage($language);
$em->remove($activity); $output->writeln('<comment>Suppression acquisitions</comment>');
$games = $em->getRepository(Game::class)->findByLanguage($language);
foreach ($games as $game) {
$scores = $em->getRepository(Score::class)->findByGame($game);
foreach ($scores as $score) {
$em->remove($score);
foreach ($score->getActivities() as $activity) {
$em->remove($activity);
}
} }
} }
}
$em->flush(); $em->flush();
$output->writeln('<comment>Suppression activity ok</comment>'); $output->writeln('<comment>Suppression activity ok</comment>');
$output->writeln('<comment>Suppression score ok</comment>'); $output->writeln('<comment>Suppression score ok</comment>');
// delete games // delete games
$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
$grids = $em->getRepository(Grid::class)->findByLanguage($language);
foreach ($grids as $grid) {
$em->remove($grid);
}
$em->flush();
$output->writeln('<comment>Suppression grilles ok</comment>');
$words = $em->getRepository(Word::class)->deleteByLanguage($language); // delete grid
$output->writeln('<comment>Suppression words ok</comment>'); $rounds = $em->getRepository(Round::class)->findByLanguage($language);
foreach ($rounds as $round) {
$em->remove($round);
}
$em->flush();
$output->writeln('<comment>Suppression Round ok</comment>');
$roots = $em->getRepository(Root::class)->deleteByLanguage($language); // delete grid
$output->writeln('<comment>Suppression roots ok</comment>'); $grids = $em->getRepository(Grid::class)->findByLanguage($language);
foreach ($grids as $grid) {
$em->remove($grid);
}
$em->flush();
$output->writeln('<comment>Suppression grilles ok</comment>');
$wordstarts = $em->getRepository(WordStart::class)->deleteByLanguage($language->getId()); $words = $em->getRepository(Word::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression wordstarts ok</comment>'); $output->writeln('<comment>Suppression words ok</comment>');
//Suppression des entités restantes pour la langue : wrongforms, foundforms, combosDone, objectivesDone $roots = $em->getRepository(Root::class)->deleteByLanguage($language);
$wrongForms = $em->getRepository(WrongForm::class)->findByLanguage($language); $output->writeln('<comment>Suppression roots ok</comment>');
foreach ($wrongForms as $wrongForm) {
$em->remove($wrongForm);
}
$em->flush();
$output->writeln('<comment>Suppression wrongForm ok</comment>');
/* $wordstarts = $em->getRepository(WordStart::class)->deleteByLanguage($language->getId());
$foundForms = $em->getRepository(FoundableForm::class)->findByLanguage($language); $output->writeln('<comment>Suppression wordstarts ok</comment>');
foreach ($foundForms as $foundForm) {
$em->remove($foundForm);
}
$em->flush();
$output->writeln('<comment>Suppression FoundForm ok</comment>');
*/
$em->remove($language); $wrongForms = $em->getRepository(WrongForm::class)->findByLanguage($language);
$output->writeln('<comment>Suppression langage ok</comment>'); foreach ($wrongForms as $wrongForm) {
$em->flush(); $em->remove($wrongForm);
}
$em->flush();
$output->writeln('<comment>Suppression wrongForm ok</comment>');
//suppression fichier bigram
$pathProject = $this->getContainer()->getParameter('languageDir');
$bigramPath = $pathProject."/data/lexicons/".$language->getValue().DIRECTORY_SEPARATOR."bigrams.txt"; $em->remove($language);
$fileSystem = new Filesystem(); $output->writeln('<comment>Suppression langage ok</comment>');
$fileSystem->remove($bigramPath); $em->flush();
$output->writeln('<comment>Suppression fichier bigrammes</comment>');
//TODO supp acquisition, et rules (ComboPoints et WordLength) //suppression fichier bigram
$pathProject = $this->getContainer()->getParameter('languageDir');
$output->writeln('<info>########### SUPPRESSION LANGUE OK ############</info>'); $bigramPath = $pathProject."/data/lexicons/".$language->getValue().DIRECTORY_SEPARATOR."bigrams.txt";
$fileSystem = new Filesystem();
$fileSystem->remove($bigramPath);
$output->writeln('<comment>Suppression fichier bigrammes</comment>');
//TODO supp acquisition, et rules (ComboPoints et WordLength)
$output->writeln('<info>########### SUPPRESSION LANGUE OK ############</info>');
} else {
$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'; echo 'Argument missing (language id)';
} }
} }
} }
...@@ -50,7 +50,7 @@ class Language ...@@ -50,7 +50,7 @@ class Language
private $relationType; private $relationType;
/** /**
* @ORM\OneToMany(targetEntity="Feature", mappedBy="language") * @ORM\OneToMany(targetEntity="Feature", mappedBy="language", cascade={"remove"})
*/ */
private $features; private $features;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace MagicWordBundle\Repository\Wordbox; namespace MagicWordBundle\Repository\Wordbox;
use MagicWordBundle\Entity\Wordbox; use MagicWordBundle\Entity\Wordbox;
use MagicWordBundle\Entity\Wordbox\Acquisition;
use LexiconBundle\Entity\Language; use LexiconBundle\Entity\Language;
class AcquisitionRepository extends \Doctrine\ORM\EntityRepository class AcquisitionRepository extends \Doctrine\ORM\EntityRepository
...@@ -23,4 +24,15 @@ class AcquisitionRepository extends \Doctrine\ORM\EntityRepository ...@@ -23,4 +24,15 @@ class AcquisitionRepository extends \Doctrine\ORM\EntityRepository
return $query->getResult(); return $query->getResult();
} }
public function deleteByLanguage(Language $language)
{
return $this->createQueryBuilder('a')
->delete(Acquisition::class, 'a')
->join('a.root', 'r')
->join('r.language', 'l', 'WITH', 'l.id = ?1', $language->getId())
->getQuery()
->getResult()
;
}
} }
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
overflow: hidden; overflow: hidden;
} }
#objectives { .top-container #objectives {
height: 100px; height: 100px;
} }
......
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