<commit_before><?php

namespace NS\ImportBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use \Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use \Symfony\Bundle\FrameworkBundle\Controller\Controller;
use \Symfony\Component\HttpFoundation\BinaryFileResponse;
use \Symfony\Component\HttpFoundation\RedirectResponse;
use \Symfony\Component\HttpFoundation\Request;
use \Symfony\Component\HttpFoundation\Response;
use \Symfony\Component\HttpFoundation\ResponseHeaderBag;

/**
 * Description of ImportController
 *
 * @author gnat
 * @Route("/{_locale}/import")
 */
class ImportController extends Controller
{
    /**
     * @param Request $request
     * @Route("/",name="importIndex")
     * @return array|RedirectResponse
     * @Method(methods={"GET","POST"})
     */
    public function indexAction(Request $request)
    {
        $entityMgr = $this->get('doctrine.orm.entity_manager');
        $form      = $this->createForm('ImportSelect', null, array('user' => $entityMgr->getReference('NS\SentinelBundle\Entity\User', $this->getUser()->getId())));

        $form->handleRequest($request);
        if ($form->isValid()) {
            $queue = $this->get('ns_import.workqueue');

            if($queue->submit($form->getData())) {
                $this->get('ns_flash')->addSuccess(null, null, "Import Added");
            } else {
                $this->get('ns_flash')->addError(null, 'Unable to add import', 'There was an error communicating with the beanstalk server');
            }

            return $this->redirect($this->generateUrl('importIndex'));
        }

        $paginator  = $this->get('knp_paginator');
        $query      = $entityMgr->getRepository('NSImportBundle:Import')->getResultsForUser($this->getUser(), 'r');
        $pagination = $paginator->paginate($query, $request->query->get('page', 1), 10);

        return $this->render('NSImportBundle:Import:index.html.twig',array('form' => $form->createView(), 'results' => $pagination));
    }

    /**
     * @param $id
     * @return Response
     *
     * @Route("/status/{id}",name="importStatus",requirements={"id"="\d+"})
     * @Method(methods={"GET"})
     */
    public function statusAction($id)
    {
        $percent = $this->get('doctrine.orm.entity_manager')->getRepository('NS\ImportBundle\Entity\Import')->getStatistics($id);

        return new Response(json_encode($percent));
    }

    /**
     * @param $id
     * @Route("/execute/{id}",name="importExecute",requirements={"id"="\d+"})
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function executeAction($id)
    {
        $worker = $this->get('ns_import.batch_worker');
        $worker->consume($id,400);

        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id integer
     * @Route("/resubmit/{id}", name="importResubmit",requirements={"id"="\d+"})
     *
     * @return RedirectResponse
     */
    public function resubmitAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');

        if($queue->reSubmit($import)) {
            $this->get('ns_flash')->addSuccess(null, null, "Import Re-Submitted");
        } else {
            $this->get('ns_flash')->addError(null, 'Unable to re-submit import', 'There was an error communicating with the beanstalk server');
        }

        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id
     * @Route("/pause/{id}",name="importDelete",requirements={"id"="\d+"})
     */
    public function deleteAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');
        $queue->delete($import);
        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id
     * @Route("/pause/{id}",name="importPause",requirements={"id"="\d+"})
     */
    public function pauseAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');
        $queue->pause($import);
        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id
     * @Route("/resume/{id}",name="importResume",requirements={"id"="\d+"})
     */
    public function resumeAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');
        $queue->resume($import);
        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @Route("/download/{type}/{id}",name="importResultDownload",requirements={"type": "success|errors|warnings|source"})
     * @param $type
     * @param $id
     * @Method(methods={"GET"})
     * @return BinaryFileResponse
     */
    public function resultDownloadAction($type, $id)
    {
        $res = $this->get('doctrine.orm.entity_manager')->getRepository('NSImportBundle:Import')->findForUser($this->getUser(), $id);
        if ($res) {
            $sourceFile = null;

            switch ($type) {<commit_msg>updated docblock<commit_after><?php

namespace NS\ImportBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use \Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use \Symfony\Bundle\FrameworkBundle\Controller\Controller;
use \Symfony\Component\HttpFoundation\BinaryFileResponse;
use \Symfony\Component\HttpFoundation\RedirectResponse;
use \Symfony\Component\HttpFoundation\Request;
use \Symfony\Component\HttpFoundation\Response;
use \Symfony\Component\HttpFoundation\ResponseHeaderBag;

/**
 * Description of ImportController
 *
 * @author gnat
 * @Route("/{_locale}/import")
 */
class ImportController extends Controller
{
    /**
     * @param Request $request
     * @Route("/",name="importIndex")
     * @return array|RedirectResponse
     * @Method(methods={"GET","POST"})
     */
    public function indexAction(Request $request)
    {
        $entityMgr = $this->get('doctrine.orm.entity_manager');
        $form      = $this->createForm('ImportSelect', null, array('user' => $entityMgr->getReference('NS\SentinelBundle\Entity\User', $this->getUser()->getId())));

        $form->handleRequest($request);
        if ($form->isValid()) {
            $queue = $this->get('ns_import.workqueue');

            if($queue->submit($form->getData())) {
                $this->get('ns_flash')->addSuccess(null, null, "Import Added");
            } else {
                $this->get('ns_flash')->addError(null, 'Unable to add import', 'There was an error communicating with the beanstalk server');
            }

            return $this->redirect($this->generateUrl('importIndex'));
        }

        $paginator  = $this->get('knp_paginator');
        $query      = $entityMgr->getRepository('NSImportBundle:Import')->getResultsForUser($this->getUser(), 'r');
        $pagination = $paginator->paginate($query, $request->query->get('page', 1), 10);

        return $this->render('NSImportBundle:Import:index.html.twig',array('form' => $form->createView(), 'results' => $pagination));
    }

    /**
     * @param $id
     * @return Response
     *
     * @Route("/status/{id}",name="importStatus",requirements={"id"="\d+"})
     * @Method(methods={"GET"})
     */
    public function statusAction($id)
    {
        $percent = $this->get('doctrine.orm.entity_manager')->getRepository('NS\ImportBundle\Entity\Import')->getStatistics($id);

        return new Response(json_encode($percent));
    }

    /**
     * @param $id
     * @Route("/execute/{id}",name="importExecute",requirements={"id"="\d+"})
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function executeAction($id)
    {
        $worker = $this->get('ns_import.batch_worker');
        $worker->consume($id,400);

        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id integer
     * @Route("/resubmit/{id}", name="importResubmit",requirements={"id"="\d+"})
     *
     * @return RedirectResponse
     */
    public function resubmitAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');

        if($queue->reSubmit($import)) {
            $this->get('ns_flash')->addSuccess(null, null, "Import Re-Submitted");
        } else {
            $this->get('ns_flash')->addError(null, 'Unable to re-submit import', 'There was an error communicating with the beanstalk server');
        }

        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id
     * @Route("/pause/{id}",name="importDelete",requirements={"id"="\d+"})
     * @return RedirectResponse
     */
    public function deleteAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');
        $queue->delete($import);
        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id
     * @Route("/pause/{id}",name="importPause",requirements={"id"="\d+"})
     * @return RedirectResponse
     */
    public function pauseAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');
        $queue->pause($import);
        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @param $id
     * @Route("/resume/{id}",name="importResume",requirements={"id"="\d+"})
     * @return RedirectResponse
     */
    public function resumeAction($id)
    {
        $import = $this->get('doctrine.orm.entity_manager')->find('NSImportBundle:Import',$id);
        $queue = $this->get('ns_import.workqueue');
        $queue->resume($import);
        return $this->redirect($this->generateUrl('importIndex'));
    }

    /**
     * @Route("/download/{type}/{id}",name="importResultDownload",requirements={"type": "success|errors|warnings|source"})
     * @param $type
     * @param $id
     * @Method(methods={"GET"})
     * @return BinaryFileResponse
     */
    public function resultDownloadAction($type, $id)
    {
        $res = $this->get('doctrine.orm.entity_manager')->getRepository('NSImportBundle:Import')->findForUser($this->getUser(), $id);
        if ($res) {
            $sourceFile = null;

            switch ($type) {
{'fraction_non_alphanumeric': 0.18670915737182492, 'fraction_numerical': 0.0011247539600712344, 'mean_word_length': 3.2782678428227747, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2762382', 'n_tokens_mistral': 3187, 'n_tokens_neox': 3120, 'n_words': 435}