Commit f68423d7 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

delete command

parent 30676f54
......@@ -11,6 +11,7 @@ use MagicWordBundle\Entity\Grid;
use MagicWordBundle\Entity\Game;
use MagicWordBundle\Entity\Round;
use MagicWordBundle\Entity\Score;
use MagicWordBundle\Entity\Wordbox\Acquisition;
use MagicWordBundle\Entity\WrongForm;
use MagicWordBundle\Entity\FoundableForm;
use MagicWordBundle\Entity\Objective;
......@@ -33,84 +34,98 @@ class DeleteLexiconCommand extends ContainerAwareCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<info>############ SUPPRESSION LANGUE #############</info>');
$em = $this->getContainer()->get('doctrine')->getEntityManager('default');
$idLexicon = $input->getArgument('id_lexicon');
if ($idLexicon) {
$language = $em->getRepository(Language::class)->find($idLexicon);
echo 'You passed an argument: ' . $idLexicon . "\n\n";
$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);
if ($language) {
$output->writeln('<info>############ SUPPRESSION LANGUE #############</info>');
echo "Suppression ".$language->getValue();
$output->writeln('<comment>Suppression acquisitions</comment>');
$em->getRepository(Acquisition::class)->deleteByLanguage($language);
$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();
$output->writeln('<comment>Suppression activity ok</comment>');
$output->writeln('<comment>Suppression score ok</comment>');
// delete games
$em->getRepository(Game::class)->deleteByLanguage($language);
$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>');
$em->flush();
$output->writeln('<comment>Suppression activity ok</comment>');
$output->writeln('<comment>Suppression score ok</comment>');
// delete games
$em->getRepository(Game::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression game ok</comment>');
$words = $em->getRepository(Word::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression words ok</comment>');
// delete grid
$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);
$output->writeln('<comment>Suppression roots 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>');
$wordstarts = $em->getRepository(WordStart::class)->deleteByLanguage($language->getId());
$output->writeln('<comment>Suppression wordstarts ok</comment>');
$words = $em->getRepository(Word::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression words ok</comment>');
//Suppression des entités restantes pour la langue : wrongforms, foundforms, combosDone, objectivesDone
$wrongForms = $em->getRepository(WrongForm::class)->findByLanguage($language);
foreach ($wrongForms as $wrongForm) {
$em->remove($wrongForm);
}
$em->flush();
$output->writeln('<comment>Suppression wrongForm ok</comment>');
$roots = $em->getRepository(Root::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression roots ok</comment>');
/*
$foundForms = $em->getRepository(FoundableForm::class)->findByLanguage($language);
foreach ($foundForms as $foundForm) {
$em->remove($foundForm);
}
$em->flush();
$output->writeln('<comment>Suppression FoundForm ok</comment>');
*/
$wordstarts = $em->getRepository(WordStart::class)->deleteByLanguage($language->getId());
$output->writeln('<comment>Suppression wordstarts ok</comment>');
$em->remove($language);
$output->writeln('<comment>Suppression langage ok</comment>');
$em->flush();
$wrongForms = $em->getRepository(WrongForm::class)->findByLanguage($language);
foreach ($wrongForms as $wrongForm) {
$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";
$fileSystem = new Filesystem();
$fileSystem->remove($bigramPath);
$output->writeln('<comment>Suppression fichier bigrammes</comment>');
$em->remove($language);
$output->writeln('<comment>Suppression langage ok</comment>');
$em->flush();
//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 {
echo 'Argument missing';
echo 'Argument missing (language id)';
}
}
}
......@@ -50,7 +50,7 @@ class Language
private $relationType;
/**
* @ORM\OneToMany(targetEntity="Feature", mappedBy="language")
* @ORM\OneToMany(targetEntity="Feature", mappedBy="language", cascade={"remove"})
*/
private $features;
......
......@@ -3,6 +3,7 @@
namespace MagicWordBundle\Repository\Wordbox;
use MagicWordBundle\Entity\Wordbox;
use MagicWordBundle\Entity\Wordbox\Acquisition;
use LexiconBundle\Entity\Language;
class AcquisitionRepository extends \Doctrine\ORM\EntityRepository
......@@ -23,4 +24,15 @@ class AcquisitionRepository extends \Doctrine\ORM\EntityRepository
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 @@
overflow: hidden;
}
#objectives {
.top-container #objectives {
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