Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathieu Loiseau
MagicWord
Commits
5971009c
Commit
5971009c
authored
May 09, 2019
by
Arnaud Bey
Browse files
add delete language grids command
parent
fe133dea
Changes
1
Show whitespace changes
Inline
Side-by-side
application/src/MagicWordBundle/Command/DeleteGridCommand.php
0 → 100644
View file @
5971009c
<?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'
;
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment