Commit 5971009c authored by Arnaud Bey's avatar Arnaud Bey
Browse files

add delete language grids command

parent fe133dea
<?php
namespace MagicWordBundle\Command;
use LexiconBundle\Manager\ImportManager;
use LexiconBundle\Entity\Language;
use LexiconBundle\Entity\Root;
use LexiconBundle\Entity\Word;
use LexiconBundle\Entity\WordStart;
use MagicWordBundle\Entity\Grid;
use MagicWordBundle\Entity\Game;
use MagicWordBundle\Entity\Round;
use MagicWordBundle\Entity\Score;
use MagicWordBundle\Entity\WrongForm;
use MagicWordBundle\Entity\FoundableForm;
use MagicWordBundle\Entity\Objective;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
class DeleteGridCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('magicword:delete-grid')
->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)
{
$output->writeln('<info>############ SUPPRESSION GRIDS #############</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);
}
$output->writeln('<comment>Suppression activity ok</comment>');
$output->writeln('<comment>Suppression score ok</comment>');
}
}
$em->flush();
$output->writeln('<comment>flush 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>');
} else {
echo 'Argument missing';
}
}
}
Supports Markdown
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