<commit_before><?php

namespace Kunstmaan\TranslatorBundle\DataFixtures\ORM;

use Kunstmaan\TranslatorBundle\Entity\Translation;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

/**
 * Fixture for creation the basic translations
 */
class TranslationFixtures extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $helloWorld = new Translation;
        $helloWorld->setKeyword('heading.hello_world');
        $helloWorld->setLocale('en');
        $helloWorld->setText('Hello World!');
        $helloWorld->setDomain('messages');
        $helloWorld->setCreatedAt(new \DateTime());
        $helloWorld->setFlag(Translation::FLAG_NEW);

        $bonjour = clone $helloWorld;
        $bonjour->setText('Bonjour tout le monde');
        $bonjour->setLocale('fr');

        $hallo = clone $helloWorld;
        $hallo->setText('Hallo wereld!');
        $hallo->setLocale('nl');

        $manager->persist($helloWorld);
        $manager->persist($bonjour);
        $manager->persist($hallo);
        $manager->flush();
    }

    /**
     * Get the order of this fixture
     *
     * @return int
     */
    public function getOrder()
    {
        return 1;
    }

}<commit_msg>Check for existing translations, before inserting fixtures<commit_after><?php

namespace Kunstmaan\TranslatorBundle\DataFixtures\ORM;

use Kunstmaan\TranslatorBundle\Entity\Translation;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

/**
 * Fixture for creation the basic translations
 */
class TranslationFixtures extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $helloWorld = new Translation;
        $helloWorld->setKeyword('heading.hello_world');
        $helloWorld->setDomain('messages');
        $helloWorld->setCreatedAt(new \DateTime());
        $helloWorld->setFlag(Translation::FLAG_NEW);

        $needForFlush = false;

        if (!$this->hasFixtureInstalled($manager, 'messages', 'heading.hello_world', 'en')) {
            $helloWorld->setLocale('en');
            $helloWorld->setText('Hello World!');
            $manager->persist($helloWorld);
            $needForFlush = true;
        }

        if (!$this->hasFixtureInstalled($manager, 'messages', 'heading.hello_world', 'fr')) {
            $bonjour = clone $helloWorld;
            $bonjour->setText('Bonjour tout le monde');
            $bonjour->setLocale('fr');
            $manager->persist($bonjour);
            $needForFlush = true;
        }

        if (!$this->hasFixtureInstalled($manager, 'messages', 'heading.hello_world', 'nl')) {
            $hallo = clone $helloWorld;
            $hallo->setText('Hallo wereld!');
            $hallo->setLocale('nl');
            $manager->persist($hallo);
            $needForFlush = true;
        }

        if ($needForFlush === true) {
            $manager->flush();
        }
    }

    public function hasFixtureInstalled(ObjectManager $manager, $domain, $keyword, $locale)
    {
        return $manager->getRepository('Kunstmaan\TranslatorBundle\Entity\Translation')->findOneBy(array('domain' => $domain, 'keyword' => $keyword, 'locale' => $locale)) instanceof \Kunstmaan\TranslatorBundle\Entity\Translation;
    }

    /**
     * Get the order of this fixture
     *
     * @return int
     */
    public function getOrder()
    {
        return 1;
    }

}
{'fraction_non_alphanumeric': 0.12996108949416343, 'fraction_numerical': 0.0005188067444876783, 'mean_word_length': 2.898887765419616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '6706086', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1082, 'n_words': 206}