<commit_before><?php

namespace KevinVR\FootbelProcessorBundle\Controller;

use Assetic\Factory\Resource\ResourceInterface;
use KevinVR\FootbelBackendBundle\Entity\Resource;
use KevinVR\FootbelBackendBundle\Repository\ResourceRepository;
use KevinVR\FootbelProcessorBundle\Processor\ResourceFileProcessor;
use KevinVR\FootbelProcessorBundle\Processor\ResourceQueueWorkerRabbitMQ;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{

    /**
     * Retrieves all resources and queues them if needed (new MD5 hash).
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     *
     * @Route("/", name="process_all")
     */
    public function processAllAction()
    {
        try {
            $queueworker = $this->get('rabbit_worker');
        } catch (\Exception $e) {
            $this->addFlash(
                'error',
                'Unable to connect to message queue.'
            );

            return $this->redirectToRoute('resource_index');
        }

        $em = $this->getDoctrine()->getManager();
        $repository = $em->getRepository("FootbelBackendBundle:Resource");

        $resources = $repository->findAll();

        foreach ($resources as $resource) {
            $resourceFileProcessor = new ResourceFileProcessor(
                $resource,
                $queueworker,
                $em
            );
            $resourceFileProcessor->process();
        }

        $this->addFlash(
            'notice',
            'All resources queued for processing!'
        );

        return $this->redirectToRoute('resource_index');
    }

    /**
     * Finds and processes a Resource entity.
     *
     * @param \KevinVR\FootbelBackendBundle\Entity\Resource $resource
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     *
     * @Route("/{id}", name="process_go")
     */
    public function processAction(Resource $resource)
    {
        try {
            $queueworker = $this->get('rabbit_worker');
        } catch (\Exception $e) {
            $this->addFlash(
                'error',
                'Unable to connect to message queue.'
            );

            return $this->redirectToRoute('resource_index');
        }

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

        $resourceFileProcessor = new ResourceFileProcessor(
            $resource,
            $queueworker,
            $em
        );
        $resourceFileProcessor->process();

        $this->addFlash(
            'notice',
            'Resource queued for processing!'
        );

        // $this->addFlash is equivalent to $this->get('session')->getFlashBag()->add

        return $this->redirectToRoute('resource_index');

    }
}<commit_msg>GA for processor<commit_after><?php

namespace KevinVR\FootbelProcessorBundle\Controller;

use Assetic\Factory\Resource\ResourceInterface;
use KevinVR\FootbelBackendBundle\Entity\Resource;
use KevinVR\FootbelBackendBundle\Repository\ResourceRepository;
use KevinVR\FootbelProcessorBundle\Processor\ResourceFileProcessor;
use KevinVR\FootbelProcessorBundle\Processor\ResourceQueueWorkerRabbitMQ;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{

    /**
     * Retrieves all resources and queues them if needed (new MD5 hash).
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     *
     * @Route("/", name="process_all")
     */
    public function processAllAction(Request $request)
    {
        try {
            $queueworker = $this->get('rabbit_worker');
        } catch (\Exception $e) {
            $this->addFlash(
                'error',
                'Unable to connect to message queue.'
            );

            $this->container->get('google_analytics')->sendData($request, 'process_all_failed');

            return $this->redirectToRoute('resource_index');
        }

        $em = $this->getDoctrine()->getManager();
        $repository = $em->getRepository("FootbelBackendBundle:Resource");

        $resources = $repository->findAll();

        foreach ($resources as $resource) {
            $resourceFileProcessor = new ResourceFileProcessor(
                $resource,
                $queueworker,
                $em
            );
            $resourceFileProcessor->process();
        }

        $this->addFlash(
            'notice',
            'All resources queued for processing!'
        );

        $this->container->get('google_analytics')->sendData($request, 'process_all');

        return $this->redirectToRoute('resource_index');
    }

    /**
     * Finds and processes a Resource entity.
     *
     * @param \KevinVR\FootbelBackendBundle\Entity\Resource $resource
     * @param \Symfony\Component\HttpFoundation\Request $request
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     *
     * @Route("/{id}", name="process_go")
     */
    public function processAction(Resource $resource, Request $request)
    {
        try {
            $queueworker = $this->get('rabbit_worker');
        } catch (\Exception $e) {
            $this->addFlash(
                'error',
                'Unable to connect to message queue.'
            );

            return $this->redirectToRoute('resource_index');
        }

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

        $resourceFileProcessor = new ResourceFileProcessor(
            $resource,
            $queueworker,
            $em
        );
        $resourceFileProcessor->process();

        $this->addFlash(
            'notice',
            'Resource queued for processing!'
        );

        $this->container->get('google_analytics')->sendData($request, 'process_one');

        return $this->redirectToRoute('resource_index');

    }
}
{'fraction_non_alphanumeric': 0.11796823295830576, 'fraction_numerical': 0.00033090668431502316, 'mean_word_length': 2.3214285714285716, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '6541577', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1524, 'n_words': 286}