<commit_before><?php
/**
 * Created by PhpStorm.
 * User: loic
 * Date: 04/01/2016
 * Time: 13:51
 */

namespace AppBundle\Command;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManager;
use JDJ\JeuBundle\Entity\Jeu;
use JDJ\LudographieBundle\Entity\Personne;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class LoadPersonsOfGamesCommand extends ContainerAwareCommand
{
    protected $writeEntityInOutput = false;

    /**
     * @inheritdoc
     */
    protected function configure()
    {
        $this
            ->setName('app:persons-of-games:load')
            ->setDescription('Load persons of games');
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        $output->writeln("<comment>Load persons of games</comment>");
        /** @var Jeu $game */
        $game = null;
        foreach ($this->getRows() as $data) {
            if (null === $game or $data['gameId'] !== $game->getId()) {
                $game = $this->getEntityManager()->getRepository('JDJJeuBundle:Jeu')->find($data['gameId']);
                $game->setAuteurs(new ArrayCollection());
                $game->setEditeurs(new ArrayCollection());
                $game->setIllustrateurs(new ArrayCollection());
                $this->getEntityManager()->flush();
            }

            /** @var Personne $person */
            $person = $this->getEntityManager()->getRepository('JDJLudographieBundle:Personne')->find($data['personId']);

            if ('auteur' === $data['job']) {
                $game->addAuteur($person);
            } elseif ('illustrateur' === $data['job']) {
                $game->addIllustrateur($person);
            } elseif ('editeur' === $data['job']) {
                $game->addEditeur($person);
            }

            $this->getEntityManager()->persist($game);
            $this->getEntityManager()->flush();
            $this->getEntityManager()->clear();
        }
    }

    /**
     * @inheritdoc
     */
    public function getRows()
    {
        $query = <<<EOM
select      old.id_game as gameId,
            old.id_personne as personId,
            old.type_relation as job
from        jedisjeux.jdj_personne_game old
inner join  jdj_jeu jeu on jeu.id = old.id_game
inner JOIN  jdj_personne person on person.id = old.id_personne
EOM;
        $rows = $this->getDatabaseConnection()->fetchAll($query);

        return $rows;
    }

    /**
     * @return EntityManager
     */
    protected function getEntityManager()
    {
        return $this->getContainer()->get('doctrine.orm.entity_manager');
    }
<commit_msg>small changes on command to load persons of game<commit_after><?php
/**
 * Created by PhpStorm.
 * User: loic
 * Date: 04/01/2016
 * Time: 13:51
 */

namespace AppBundle\Command;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManager;
use JDJ\JeuBundle\Entity\Jeu;
use JDJ\LudographieBundle\Entity\Personne;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class LoadPersonsOfGamesCommand extends ContainerAwareCommand
{
    protected $writeEntityInOutput = false;

    /**
     * @inheritdoc
     */
    protected function configure()
    {
        $this
            ->setName('app:persons-of-games:load')
            ->setDescription('Load persons of games');
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        $output->writeln("<comment>Load persons of games</comment>");
        /** @var Jeu $game */
        $game = null;
        foreach ($this->getRows() as $data) {
            if (null === $game or $data['gameId'] !== $game->getId()) {
                $game = $this->getEntityManager()->getRepository('JDJJeuBundle:Jeu')->find($data['gameId']);
                $game->setAuteurs(new ArrayCollection());
                $game->setEditeurs(new ArrayCollection());
                $game->setIllustrateurs(new ArrayCollection());
                $this->getEntityManager()->flush();
            }

            /** @var Personne $person */
            $person = $this->getEntityManager()->getRepository('JDJLudographieBundle:Personne')->find($data['personId']);

            if ('auteur' === $data['job']) {
                $game->addAuteur($person);
            } elseif ('illustrateur' === $data['job']) {
                $game->addIllustrateur($person);
            } elseif ('editeur' === $data['job']) {
                $game->addEditeur($person);
            }

            $this->getEntityManager()->persist($game);
            $this->getEntityManager()->flush();
            $this->getEntityManager()->clear();
        }

    }

    /**
     * @inheritdoc
     */
    public function getRows()
    {
        $query = <<<EOM
select      old.id_game as gameId,
            old.id_personne as personId,
            old.type_relation as job
from        jedisjeux.jdj_personne_game old
inner join  jdj_jeu jeu on jeu.id = old.id_game
inner JOIN  jdj_personne person on person.id = old.id_personne
order by    old.id_game
EOM;
        $rows = $this->getDatabaseConnection()->fetchAll($query);

        return $rows;
    }

    /**
     * @return EntityManager
     */
    protected function getEntityManager()
    {
        return $this->getContainer()->get('doctrine.orm.entity_manager');
    }

{'fraction_non_alphanumeric': 0.14805149617258176, 'fraction_numerical': 0.0041753653444676405, 'mean_word_length': 2.4363419007770473, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3516014', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1671, 'n_words': 307}