<commit_before><?php
/**
 * Created by PhpStorm.
 * User: loic
 * Date: 12/02/2016
 * Time: 13:40
 */

namespace AppBundle\Command;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class LoadAvatarsOfUsersCommand extends ContainerAwareCommand
{
    /**
     * @var ObjectManager
     */
    private $manager;

    protected $output;

    protected function configure()
    {
        $this
            ->setName('app:avatars-of-users:load')
            ->setDescription('Loading avatars of users');
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var EntityManager $manager */
        $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
        $this->load($manager);
    }

    /**
     * @return \Doctrine\DBAL\Connection
     */
    public function getDatabaseConnection()
    {
        return $this->getContainer()->get('database_connection');
    }

    /**
     * {@inheritdoc}
     */
    public function load(ObjectManager $manager)
    {
        $this->manager = $manager;

        $query = <<<EOM
insert into jdj_customer_avatar (id, path)
select      distinct old.user_id, user_avatar
from        jedisjeux.phpbb3_users old
where not exists (
    select 0
    from   jdj_customer_avatar i
    where  i.id = old.user_id
)
and old.user_avatar <> ''
EOM;

        $this->getDatabaseConnection()->executeQuery($query);

        $query = <<<EOM
update   fos_user user
inner join jdj_customer_avatar avatar on avatar.id = user.id
    set user.avatar_id = avatar.id
EOM;

        $this->getDatabaseConnection()->executeQuery($query);
    }
}<commit_msg>fix load avatars of users command<commit_after><?php
/**
 * Created by PhpStorm.
 * User: loic
 * Date: 12/02/2016
 * Time: 13:40
 */

namespace AppBundle\Command;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class LoadAvatarsOfUsersCommand extends ContainerAwareCommand
{
    /**
     * @var ObjectManager
     */
    private $manager;

    protected $output;

    protected function configure()
    {
        $this
            ->setName('app:avatars-of-users:load')
            ->setDescription('Loading avatars of users');
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var EntityManager $manager */
        $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
        $this->load($manager);
    }

    /**
     * @return \Doctrine\DBAL\Connection
     */
    public function getDatabaseConnection()
    {
        return $this->getContainer()->get('database_connection');
    }

    /**
     * {@inheritdoc}
     */
    public function load(ObjectManager $manager)
    {
        $this->manager = $manager;

        $query = <<<EOM
insert into jdj_customer_avatar (id, path)
select      distinct old.user_id, user_avatar
from        jedisjeux.phpbb3_users old
where not exists (
    select 0
    from   jdj_customer_avatar i
    where  i.id = old.user_id
)
and old.user_avatar <> ''
EOM;

        $this->getDatabaseConnection()->executeQuery($query);

        $query = <<<EOM
update   sylius_customer customer
inner join jdj_customer_avatar avatar on customer.code = concat('user-', avatar.id)
    set customer.avatar_id = avatar.id
EOM;

        $this->getDatabaseConnection()->executeQuery($query);
    }
}
{'fraction_non_alphanumeric': 0.12506459948320414, 'fraction_numerical': 0.007235142118863049, 'mean_word_length': 2.9101010101010103, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, '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': '3308996', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1164, 'n_words': 240}