<commit_before><?php

namespace Furniture\ProductBundle\Controller;

use Sylius\Bundle\ProductBundle\Controller\VariantController as BaseVariantController;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Furniture\ProductBundle\Model\GroupVaraintFilter;
use Furniture\ProductBundle\Form\Type\GroupVariantFilterType;

class VariantController extends BaseVariantController
{
    /**
     * {@inheritDoc}
     */
    public function deleteAction(Request $request)
    {
        $hardDelete = $request->get('hard');
        $em = $this->get('doctrine.orm.default_entity_manager');

        if ($hardDelete) {
            $em->getFilters()->disable('softdeleteable');
        }

        $response = parent::deleteAction($request);

        if ($hardDelete) {
            $em->getFilters()->enable('softdeleteable');
        }

        if ($request->get('_from')) {
            return new RedirectResponse($request->get('_from'));
        }

        return $response;
    }

    /**
     * {@inheritDoc}
     */
    public function restoreAction(Request $request)
    {
        $response = parent::restoreAction($request);

        if ($request->get('_from')) {
            return new RedirectResponse($request->get('_from'));
        }

        return $response;
    }

    /**
     * Clear deleted variants
     *
     * @param Request $request
     * @param int     $productId
     *
     * @return RedirectResponse
     */
    public function clearDeletedAction(Request $request, $productId)
    {
        $em = $this->get('doctrine.orm.default_entity_manager');
        $em->getFilters()->disable('softdeleteable');

        /** @var \Furniture\ProductBundle\Entity\Product $product */
        $product = $this->findProductOr404($productId);
        $deletedVariants = $product->getDeletedVariants();

        foreach ($deletedVariants as $variant) {
            $em->remove($variant);
        }

        $em->flush();

        $em->getFilters()->enable('softdeleteable');

        if ($request->get('_from')) {
            return new RedirectResponse($request->get('_from'));
        }

        return $this->redirectHandler->redirectToIndex();
    }

    /**
     * Get variant generator.
     *
     * @return \Furniture\ProductBundle\Generator\VariantGenerator
     */
    protected function getGenerator()
    {
        return $this->get('Furniture.generator.product_variant');
    }
    
    /**
     * Generate all possible variants for given product id.
     *
     * @param Request $request
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function generateAction(Request $request)
    {
        if (null === $productId = $request->get('productId')) {
            throw new NotFoundHttpException('No product given.');
        }

        /** @var \Furniture\ProductBundle\Entity\Product $product */
        $product = $this->findProductOr404($productId);
        
        $form = $this->createForm(new GroupVariantFilterType, new \Furniture\ProductBundle\Model\GroupVaraintFiler($product) );
        
        $form->handleRequest($request);
        
        if ($form->isValid()) {
            $filter = $form->getData();
            $this->getGenerator()->generateByFilter($filter);
            $manager = $this->get('sylius.manager.product');
            $manager->persist($filter->getProduct());
            $manager->flush();
        }

        $this->flashHelper->setFlash('success', 'generate');

        $view = $this
                ->view([
                    'product' => $product,
                    'form' => $form->createView(),
                ])
                ->setTemplate($this->config->getTemplate('generate.html'));

        return $this->handleView($view);
    }
    
}
<commit_msg>Fix bug with generate url button<commit_after><?php

namespace Furniture\ProductBundle\Controller;

use Sylius\Bundle\ProductBundle\Controller\VariantController as BaseVariantController;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Furniture\ProductBundle\Model\GroupVaraintFilter;
use Furniture\ProductBundle\Form\Type\GroupVariantFilterType;

class VariantController extends BaseVariantController
{
    /**
     * {@inheritDoc}
     */
    public function deleteAction(Request $request)
    {
        $hardDelete = $request->get('hard');
        $em = $this->get('doctrine.orm.default_entity_manager');

        if ($hardDelete) {
            $em->getFilters()->disable('softdeleteable');
        }

        $response = parent::deleteAction($request);

        if ($hardDelete) {
            $em->getFilters()->enable('softdeleteable');
        }

        if ($request->get('_from')) {
            return new RedirectResponse($request->get('_from'));
        }

        return $response;
    }

    /**
     * {@inheritDoc}
     */
    public function restoreAction(Request $request)
    {
        $response = parent::restoreAction($request);

        if ($request->get('_from')) {
            return new RedirectResponse($request->get('_from'));
        }

        return $response;
    }

    /**
     * Clear deleted variants
     *
     * @param Request $request
     * @param int     $productId
     *
     * @return RedirectResponse
     */
    public function clearDeletedAction(Request $request, $productId)
    {
        $em = $this->get('doctrine.orm.default_entity_manager');
        $em->getFilters()->disable('softdeleteable');

        /** @var \Furniture\ProductBundle\Entity\Product $product */
        $product = $this->findProductOr404($productId);
        $deletedVariants = $product->getDeletedVariants();

        foreach ($deletedVariants as $variant) {
            $em->remove($variant);
        }

        $em->flush();

        $em->getFilters()->enable('softdeleteable');

        if ($request->get('_from')) {
            return new RedirectResponse($request->get('_from'));
        }

        return $this->redirectHandler->redirectToIndex();
    }

    /**
     * Get variant generator.
     *
     * @return \Furniture\ProductBundle\Generator\VariantGenerator
     */
    protected function getGenerator()
    {
        return $this->get('Furniture.generator.product_variant');
    }
    
    /**
     * Generate all possible variants for given product id.
     *
     * @param Request $request
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function generateAction(Request $request)
    {
        if (null === $productId = $request->get('productId')) {
            throw new NotFoundHttpException('No product given.');
        }

        /** @var \Furniture\ProductBundle\Entity\Product $product */
        $product = $this->findProductOr404($productId);
        
        $form = $this->createForm(new GroupVariantFilterType, new \Furniture\ProductBundle\Model\GroupVaraintFiler($product) );
        
        $form->handleRequest($request);
        
        if ($form->isValid()) {
            $filter = $form->getData();
            $this->getGenerator()->generateByFilter($filter);
            $manager = $this->get('sylius.manager.product');
            $manager->persist($filter->getProduct());
            $manager->flush();
            $this->flashHelper->setFlash('success', 'generate');
        }

        $view = $this
                ->view([
                    'product' => $product,
                    'form' => $form->createView(),
                ])
                ->setTemplate($this->config->getTemplate('generate.html'));

        return $this->handleView($view);
    }
    
}

{'fraction_non_alphanumeric': 0.1419005923255215, 'fraction_numerical': 0.001545197012619109, 'mean_word_length': 2.387265590928914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, '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': '5829880', 'n_tokens_mistral': 2109, 'n_tokens_neox': 2065, 'n_words': 339}