<commit_before><?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Client;
use AppBundle\Entity\User;

/**
 * @Route("/behat")
 */
class BehatController extends RestController
{
    /**
     * @Route("/email")
     * @Method({"GET"})
     */
    public function emailAction()
    {
        $mailPath = $this->getBehatMailFilePath();
        
        if (!file_exists($mailPath)) {
            throw new \RuntimeException("Mail log $mailPath not existing.");
        }
        
        if (!is_readable($mailPath)) {
            throw new \RuntimeException("Mail log $mailPath unreadable.");
        }
        
        return file_get_contents($mailPath);
    }
    
    
    /**
     * @Route("/report/{reportId}")
     * @Method({"PUT"})
     */
    public function reportChangeCotAction(Request $request, $reportId)
    {
        $report = $this->findEntityBy('Report', $reportId);
        
        $data = $this->deserializeBodyContent($request);
        
        if (!empty($data['cotId'])) {
            $cot = $this->findEntityBy('CourtOrderType', $data['cotId']);
            $report->setCourtOrderType($cot);
        }
        
        if (array_key_exists('submitted', $data)) {
            $report->setSubmitted($data['submitted']);
            $report->setSubmitDate($data['submitted'] ? new \DateTime : null);
        }
        
        if (array_key_exists('end_date', $data)) {
            $report->setEndDate(new \DateTime($data['end_date']));
        }
        
        $this->get('em')->flush($report);
        
        return true;
    }
    
    
    
    /**
     * @Route("/check-app-params")
     * @Method({"GET"})
     */
    public function checkParamsAction()
    {
        $param = $this->container->getParameter('email_report_submit')['to_email'];
        if (!preg_match('/^behat\-/', $param)) {
            throw new DisplayableException("email_report_submit.to_email must be a behat- email in order to test emails, $param given.");
        }
        
        $param = $this->container->getParameter('email_feedback_send')['to_email'];
        if (!preg_match('/^behat\-/', $param)) {
            throw new DisplayableException("email_feedback_send.to_email must be a behat- email in order to test emails, $param given.");
        }
        
        return "valid";
    }
    
    /**
     * @Route("/audit-log")
     * @Method({"GET"})
     */
    public function auditLogGetAllAction()
    {
        $this->setJmsSerialiserGroups(['audit_log']);

        return $this->getRepository('AuditLogEntry')->findBy([], ['id'=>'DESC']);
    }
    
     /**
     * @Route("/user/{email}")
     * @Method({"PUT"})
     */
    public function editUser(Request $request, $email)
    {
        $data = $this->deserializeBodyContent($request);
        $user = $this->getRepository('User')->findBy(['email'=>$email]);
        
        if (!empty($data['registration_token'])) {
            $user->setRegistrationToken($data['registration_token']);
        }
        
        if (!empty($data['token_date'])) { //important, keep this after "setRegistrationToken" otherwise date will be reset
            $user->setTokenDate(new \DateTime($data['token_date']));
        }
        
        return "done";<commit_msg>dd-1130 fix behat set user token<commit_after><?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Client;
use AppBundle\Entity\User;

/**
 * @Route("/behat")
 */
class BehatController extends RestController
{
    /**
     * @Route("/email")
     * @Method({"GET"})
     */
    public function emailAction()
    {
        $mailPath = $this->getBehatMailFilePath();
        
        if (!file_exists($mailPath)) {
            throw new \RuntimeException("Mail log $mailPath not existing.");
        }
        
        if (!is_readable($mailPath)) {
            throw new \RuntimeException("Mail log $mailPath unreadable.");
        }
        
        return file_get_contents($mailPath);
    }
    
    
    /**
     * @Route("/report/{reportId}")
     * @Method({"PUT"})
     */
    public function reportChangeCotAction(Request $request, $reportId)
    {
        $report = $this->findEntityBy('Report', $reportId);
        
        $data = $this->deserializeBodyContent($request);
        
        if (!empty($data['cotId'])) {
            $cot = $this->findEntityBy('CourtOrderType', $data['cotId']);
            $report->setCourtOrderType($cot);
        }
        
        if (array_key_exists('submitted', $data)) {
            $report->setSubmitted($data['submitted']);
            $report->setSubmitDate($data['submitted'] ? new \DateTime : null);
        }
        
        if (array_key_exists('end_date', $data)) {
            $report->setEndDate(new \DateTime($data['end_date']));
        }
        
        $this->get('em')->flush($report);
        
        return true;
    }
    
    
    
    /**
     * @Route("/check-app-params")
     * @Method({"GET"})
     */
    public function checkParamsAction()
    {
        $param = $this->container->getParameter('email_report_submit')['to_email'];
        if (!preg_match('/^behat\-/', $param)) {
            throw new DisplayableException("email_report_submit.to_email must be a behat- email in order to test emails, $param given.");
        }
        
        $param = $this->container->getParameter('email_feedback_send')['to_email'];
        if (!preg_match('/^behat\-/', $param)) {
            throw new DisplayableException("email_feedback_send.to_email must be a behat- email in order to test emails, $param given.");
        }
        
        return "valid";
    }
    
    /**
     * @Route("/audit-log")
     * @Method({"GET"})
     */
    public function auditLogGetAllAction()
    {
        $this->setJmsSerialiserGroups(['audit_log']);

        return $this->getRepository('AuditLogEntry')->findBy([], ['id'=>'DESC']);
    }
    
     /**
     * @Route("/user/{email}")
     * @Method({"PUT"})
     */
    public function editUser(Request $request, $email)
    {
        $data = $this->deserializeBodyContent($request);
        $user = $this->findEntityBy('User', ['email'=>$email]);
        
        if (!empty($data['registration_token'])) {
            $user->setRegistrationToken($data['registration_token']);
        }
        
        if (!empty($data['token_date'])) { //important, keep this after "setRegistrationToken" otherwise date will be reset
            $user->setTokenDate(new \DateTime($data['token_date']));
        }
        
        $this->get('em')->flush($user);
        
        return "done";
{'fraction_non_alphanumeric': 0.16163206871868288, 'fraction_numerical': 0.000572655690765927, 'mean_word_length': 2.3797774552491533, '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': '5441366', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1999, 'n_words': 338}