<commit_before><?php

namespace AndreasGlaser\DCEventBundle\EventListener;

use AndreasGlaser\DCEventBundle\EventHandler\Annotations\DCEntityEventHandlerReader;
use AndreasGlaser\DCEventBundle\EventHandler\DCCommonEntityEventHandlerBase;
use AndreasGlaser\DCEventBundle\EventHandler\DCEntityEventHandlerBase;
use AndreasGlaser\DCEventBundle\Helper\ChangeSetHelper;
use AndreasGlaser\DCEventBundle\Helper\FlagHelper;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Event\PostFlushEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\UnitOfWork;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class DCEventListener
 *
 * @package AndreasGlaser\DCEventBundle\EventListener
 * @author  <NAME>
 */
class DCEventListener implements EventSubscriber, ContainerAwareInterface
{
    /**
     * @var EntityManager
     */
    protected $entityManager;

    /**
     * @var UnitOfWork
     */
    protected $unitOfWork;

    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @var array
     */
    protected $recalculationQueue = [];

    /**
     * @var array
     */
    protected $entityEventHandlerCache = [];

    /**
     * @var DCCommonEntityEventHandlerBase
     */
    protected $commonEntityEventHandler;

    /**
     * @var array
     */
    protected $processedEntities = [
        'persist' => [],
        'update'  => [],
        'remove'  => []
    ];

    /**
     * @var array
     */
    protected $config = [];

    /**
     * @var \AndreasGlaser\DCEventBundle\Helper\FlagHelper
     */
    protected $flagHelper;

    /**
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
        $this->setContainer($container);
        $this->config = $this->container->getParameter('andreas_glaser_dc_event');
        $this->flagHelper = FlagHelper::factory();
    }

    /**
     * @inheritdoc
     */
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    /**
     * @inheritdoc
     */
    public function getSubscribedEvents()
    {
        return ['preFlush', 'postFlush'];
    }

    /**
     * @param \Doctrine\ORM\Event\PreFlushEventArgs $eventArgs
     *
     * @author <NAME>
     */
    public function preFlush(PreFlushEventArgs $eventArgs)
    {
        $this->entityManager = $eventArgs->getEntityManager();
        $this->unitOfWork = $this->entityManager->getUnitOfWork();<commit_msg>Fixed issue related to multiple consecutive flushes<commit_after><?php

namespace AndreasGlaser\DCEventBundle\EventListener;

use AndreasGlaser\DCEventBundle\EventHandler\Annotations\DCEntityEventHandlerReader;
use AndreasGlaser\DCEventBundle\EventHandler\DCCommonEntityEventHandlerBase;
use AndreasGlaser\DCEventBundle\EventHandler\DCEntityEventHandlerBase;
use AndreasGlaser\DCEventBundle\Helper\ChangeSetHelper;
use AndreasGlaser\DCEventBundle\Helper\FlagHelper;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Event\PostFlushEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\UnitOfWork;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class DCEventListener
 *
 * @package AndreasGlaser\DCEventBundle\EventListener
 * @author  <NAME>
 */
class DCEventListener implements EventSubscriber, ContainerAwareInterface
{
    /**
     * @var EntityManager
     */
    protected $entityManager;

    /**
     * @var UnitOfWork
     */
    protected $unitOfWork;

    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @var array
     */
    protected $recalculationQueue = [];

    /**
     * @var array
     */
    protected $entityEventHandlerCache = [];

    /**
     * @var DCCommonEntityEventHandlerBase
     */
    protected $commonEntityEventHandler;

    /**
     * @var array
     */
    protected $processedEntities = [
        'persist' => [],
        'update'  => [],
        'remove'  => [],
    ];

    /**
     * @var array
     */
    protected $config = [];

    /**
     * @var \AndreasGlaser\DCEventBundle\Helper\FlagHelper
     */
    protected $flagHelper;

    /**
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
        $this->setContainer($container);
        $this->config = $this->container->getParameter('andreas_glaser_dc_event');
        $this->flagHelper = FlagHelper::factory();
    }

    /**
     * Resets temporary values
     *
     * @author <NAME>
     */
    protected function reset()
    {
        $this->recalculationQueue = [];
        $this->entityEventHandlerCache = [];
        $this->commonEntityEventHandler = null;
        $this->processedEntities = [
            'persist' => [],
            'update'  => [],
            'remove'  => [],
        ];
        $this->flagHelper = FlagHelper::factory();
    }

    /**
     * @inheritdoc
     */
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    /**
     * @inheritdoc
     */
    public function getSubscribedEvents()
    {
        return ['preFlush', 'postFlush'];
    }

    /**
     * @param \Doctrine\ORM\Event\PreFlushEventArgs $eventArgs
     *
     * @author <NAME>
     */
    public function preFlush(PreFlushEventArgs $eventArgs)
    {
        $this->reset();

        $this->entityManager = $eventArgs->getEntityManager();
        $this->unitOfWork = $this->entityManager->getUnitOfWork();
{'fraction_non_alphanumeric': 0.12162391710548666, 'fraction_numerical': 0.0, 'mean_word_length': 2.8839050131926123, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 45, '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': '6518690', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1688, 'n_words': 262}