<commit_before><?php

namespace Samson\Bundle\DataGridBundle\Controller;

use Samson\Bundle\DataGridBundle\Helper\Exception\ValidationException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

abstract class AbstractDataGridController extends Controller
{

    /**
     * @return ControllerHelperConfiguration
     */
    abstract protected function getHelperConfiguration();

    protected function getHelper()
    {
        return $this->get('samson_datagrid.controller_helper');
    }

    protected function getList($entities)
    {
        return $this->getHelper()->index($this->getHelperConfiguration()->getView(), $entities);
    }

    protected function handleEdit($entity)
    {

        $em = $this->getDoctrine()->getManager();

        $options = $this->getHelperConfiguration()->getOptions();
        try {
            $this->getHelper()->update($entity, $this->getHelperConfiguration()->getFormType(), json_decode($this->getRequest()->getContent(), true), $options['form_options']);
        } catch (ValidationException $e) {
            return new Response($this->get('jms_serializer')->serialize($e->getForm(), 'json'), 400);
        }

        $em->flush();
        $view = $this->getHelperConfiguration()->getView();
        $view->serialize($entity);

        return new Response($this->get('jms_serializer')->serialize($view->getData(), 'json'));
    }

    protected function handleCreate($entity)
    {
        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        return call_user_func_array(array($this, 'handleEdit'), func_get_args());
    }

    protected function handleDelete($entity)
    {<commit_msg>moved persisting of entity to later place because of possible problems with doctrine in edge cases<commit_after><?php

namespace Samson\Bundle\DataGridBundle\Controller;

use Samson\Bundle\DataGridBundle\Helper\Exception\ValidationException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

abstract class AbstractDataGridController extends Controller
{

    /**
     * @return ControllerHelperConfiguration
     */
    abstract protected function getHelperConfiguration();

    protected function getHelper()
    {
        return $this->get('samson_datagrid.controller_helper');
    }

    protected function getList($entities)
    {
        return $this->getHelper()->index($this->getHelperConfiguration()->getView(), $entities);
    }

    protected function handleEdit($entity)
    {

        $em = $this->getDoctrine()->getManager();

        $options = $this->getHelperConfiguration()->getOptions();
        try {
            $this->getHelper()->update($entity, $this->getHelperConfiguration()->getFormType(), json_decode($this->getRequest()->getContent(), true), $options['form_options']);
        } catch (ValidationException $e) {
            return new Response($this->get('jms_serializer')->serialize($e->getForm(), 'json'), 400);
        }

        $em->persist($entity);
        $em->flush();
        $view = $this->getHelperConfiguration()->getView();
        $view->serialize($entity);

        return new Response($this->get('jms_serializer')->serialize($view->getData(), 'json'));
    }

    protected function handleCreate($entity)
    {
        $em = $this->getDoctrine()->getManager();
        return call_user_func_array(array($this, 'handleEdit'), func_get_args());
    }

    protected function handleDelete($entity)
    {
{'fraction_non_alphanumeric': 0.14621988368872887, 'fraction_numerical': 0.001661589587371919, 'mean_word_length': 3.816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '5513604', 'n_tokens_mistral': 950, 'n_tokens_neox': 933, 'n_words': 165}