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;
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,14 +34,21 @@ 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";
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) {
......@@ -60,6 +68,15 @@ class DeleteLexiconCommand extends ContainerAwareCommand
$em->getRepository(Game::class)->deleteByLanguage($language);
$output->writeln('<comment>Suppression game 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>');
// delete grid
$grids = $em->getRepository(Grid::class)->findByLanguage($language);
foreach ($grids as $grid) {
......@@ -77,7 +94,6 @@ class DeleteLexiconCommand extends ContainerAwareCommand
$wordstarts = $em->getRepository(WordStart::class)->deleteByLanguage($language->getId());
$output->writeln('<comment>Suppression wordstarts 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);
......@@ -85,14 +101,6 @@ class DeleteLexiconCommand extends ContainerAwareCommand
$em->flush();
$output->writeln('<comment>Suppression wrongForm 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>');
*/
$em->remove($language);
$output->writeln('<comment>Suppression langage ok</comment>');
......@@ -110,7 +118,14 @@ class DeleteLexiconCommand extends ContainerAwareCommand
$output->writeln('<info>########### SUPPRESSION LANGUE OK ############</info>');
} else {
echo 'Argument missing';
$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 (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