<commit_before><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace RestApi\FilesBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use RestApi\FilesBundle\Entity\FileModel;
use RestApi\FilesBundle\Form\FileModelType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
/**
 * Description of FilesController
 *
 * @author nairi
 */
class FilesController extends Controller {


     
    public function addFileAction($id = null, Request $request) {
        
         if ($request->isMethod('POST')) {
            return $this->fileGeneratorAction($id, $request);
        }
    }

    public function fileGeneratorAction($id = null, Request $request) {


        $insert_data = new FileModel();
        $form = $this->createForm(FileModelType::class, $insert_data);
        $form->handleRequest($request);
        $file = $insert_data->getFile();

        if (!is_null($file)) {
            $file_hash_name = md5(uniqid()) . '.' . $file->guessExtension();

            $date = date("Y-m-d m:s:i");
            $date = new\DateTime($date);

            $file->move(
                    'files', $file_hash_name
            );

            if (!is_null($id)) {
                $em = $this->getDoctrine()->getManager();
                $DBdata = $em->getRepository('RestApiFilesBundle:FileModel')->find($id);
            } else {
                $insert_data->setCreated($date);
                $em = $this->getDoctrine()->getManager();
            }

            $insert_data->setUpdated($date);
            $insert_data->setFileHashName($file_hash_name);
            $em->persist($insert_data);

            $em->flush();
            $message = "{'message':'File created'}";
            echo $message."\n";
            $process = new Process("git commit -a -m 'add file ".$file_hash_name."' && git push");
                try {
                    $process->setPty(true);
                    $process->mustRun(function ($type, $buffer) {
                        echo $buffer;
                     });
                 } catch (ProcessFailedException $e) {<commit_msg>'change'<commit_after><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace RestApi\FilesBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use RestApi\FilesBundle\Entity\FileModel;
use RestApi\FilesBundle\Form\FileModelType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
/**
 * Description of FilesController
 *
 * @author nairi
 */
class FilesController extends Controller {


     
    public function addFileAction($id = null, Request $request) {
        
         if ($request->isMethod('POST')) {
            return $this->fileGeneratorAction($id, $request);
        }
    }

    public function fileGeneratorAction($id = null, Request $request) {


        $insert_data = new FileModel();
        $form = $this->createForm(FileModelType::class, $insert_data);
        $form->handleRequest($request);
        $file = $insert_data->getFile();

        if (!is_null($file)) {
            $file_hash_name = md5(uniqid()) . '.' . $file->guessExtension();

            $date = date("Y-m-d m:s:i");
            $date = new\DateTime($date);

            $file->move(
                    'files', $file_hash_name
            );

            if (!is_null($id)) {
                $em = $this->getDoctrine()->getManager();
                $DBdata = $em->getRepository('RestApiFilesBundle:FileModel')->find($id);
            } else {
                $insert_data->setCreated($date);
                $em = $this->getDoctrine()->getManager();
            }

            $insert_data->setUpdated($date);
            $insert_data->setFileHashName($file_hash_name);
            $em->persist($insert_data);

            $em->flush();
            $message = "{'message':'File created'}";
            echo $message."\n";
            $process = new Process("git commit -a -m 'change' && git push");
                try {
                    $process->setPty(true);
                    $process->mustRun(function ($type, $buffer) {
                        echo $buffer;
                     });
                 } catch (ProcessFailedException $e) {
{'fraction_non_alphanumeric': 0.13677555321390938, 'fraction_numerical': 0.00042149631190727084, 'mean_word_length': 2.2219959266802443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '3628369', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1264, 'n_words': 260}