<commit_before><?php

namespace Brzozowski\IntelliHomeBundle\Controller;

use Brzozowski\IntelliHomeBundle\Entity\HeatingStatistics;
use Brzozowski\IntelliHomeBundle\Entity\Notifications;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Brzozowski\IntelliHomeBundle\Entity\Logs;
use Brzozowski\IntelliHomeBundle\Entity\Alarm;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route(
 *     "/arduino",
 *     name="incoming_arduino_data"
 * )
 */
class IncomingArduinoDataController extends Controller
{
    /**
     * @Route(
     *     "/uruchom_alarm_wlamanie.php",
     *     name="arduino_activate_alarm_breakin"
     * )
     * @param Request $request
     * @return Response
     */
    public function activateAlarmOrBreakinAction(Request $request)
    {
        $alarmStatus = $request->query->get('alarm');

        if($alarmStatus == 'p' or $alarmStatus == 'A' or $alarmStatus == 'B' or $alarmStatus == 'C' or $alarmStatus == 'D'
            or $alarmStatus == 'b' or $alarmStatus == 'l' or $alarmStatus == 'U')
        {

            switch($alarmStatus)
            {
                case 'A': {
                    $personId = 1;
                    break;
                }
                case 'B': {
                    $personId = 2;
                    break;
                }
                case 'C': {
                    $personId = 3;
                    break;
                }
                case 'D': {
                    $personId = 4;
                    break;
                }
                case 'p': {
                    $personId = 5;
                    break;
                }
                case 'b': {
                    $personId = 6;
                    $message = "Włamanie !!!";
                    $type = 'danger';
                    $status = 'BREAKIN';
                    break;
                }
                case 'l': {
                    $personId = 6;
                    $status = 'ON';
                    $message = null;
                    $type = null;
                    break;
                }
                case 'U': {
                    $message = "System IntelliHome został zrestartowany. Alarm zdezaktywowany.";
                    $type = 'info';
                    $personId = 6;
                    $status = 'OFF';
                    break;
                }
                default: {
                    $personId = 6;
                    $status = '';
                    $message = null;
                    $type = null;

                    //return new Response(Response::HTTP_BAD_REQUEST);
                }
            }

            $em = $this->getDoctrine()->getManager();
            $dateTime = new \DateTime();

            if($personId < 6) {
                $status = "CHANGE";
                $Repo = $this->getDoctrine()->getRepository('BrzozowskiIntelliHomeBundle:Persons');
                $person = $Repo->findOneBy(
                    array('id' => $personId)
                );
                $name = $person->getName();
                $message = "Użytkownik ".$name." aktywował alarm przy użyciu swojej karty";
            }

            // Save alarm status
            $alarm = new Alarm();
            $alarm->setDate($dateTime);
            $alarm->setTime($dateTime);
            $alarm->setWho($personId);
            $alarm->setStatus($status);
            $em->persist($alarm);
            $em->flush();

            // Save log
            if($message) {
                $log = new Logs();
                $log->setDate($dateTime)->setTime($dateTime)->setContent($message);
                $em = $this->getDoctrine()->getManager();
                $em->persist($log);
                $em->flush();
            }

            // Save notif
            if($type) {
                $notif = new Notifications($type, $message);
                $em->persist($notif);
                $em->flush();
            }

            if($alarmStatus == 'b') return $this->redirectToRoute('send_sms');

            return new Response(Response::HTTP_OK);
        }

        return new Response(Response::HTTP_BAD_REQUEST);
    }

<commit_msg>Repair SMS notify after alarm brake-in<commit_after><?php

namespace Brzozowski\IntelliHomeBundle\Controller;

use Brzozowski\IntelliHomeBundle\Entity\HeatingStatistics;
use Brzozowski\IntelliHomeBundle\Entity\Notifications;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Brzozowski\IntelliHomeBundle\Entity\Logs;
use Brzozowski\IntelliHomeBundle\Entity\Alarm;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route(
 *     "/arduino",
 *     name="incoming_arduino_data"
 * )
 */
class IncomingArduinoDataController extends Controller
{
    /**
     * @Route(
     *     "/uruchom_alarm_wlamanie.php",
     *     name="arduino_activate_alarm_breakin"
     * )
     * @param Request $request
     * @return Response
     */
    public function activateAlarmOrBreakinAction(Request $request)
    {
        $alarmStatus = $request->query->get('alarm');

        if($alarmStatus == 'p' or $alarmStatus == 'A' or $alarmStatus == 'B' or $alarmStatus == 'C' or $alarmStatus == 'D'
            or $alarmStatus == 'b' or $alarmStatus == 'l' or $alarmStatus == 'U')
        {

            switch($alarmStatus)
            {
                case 'A': {
                    $personId = 1;
                    break;
                }
                case 'B': {
                    $personId = 2;
                    break;
                }
                case 'C': {
                    $personId = 3;
                    break;
                }
                case 'D': {
                    $personId = 4;
                    break;
                }
                case 'p': {
                    $personId = 5;
                    break;
                }
                case 'b': {
                    $personId = 6;
                    $message = "Włamanie !!!";
                    $type = 'danger';
                    $status = 'BREAKIN';
                    break;
                }
                case 'l': {
                    $personId = 6;
                    $status = 'ON';
                    $message = null;
                    $type = null;
                    break;
                }
                case 'U': {
                    $message = "System IntelliHome został zrestartowany. Alarm zdezaktywowany.";
                    $type = 'info';
                    $personId = 6;
                    $status = 'OFF';
                    break;
                }
                default: {
                    $personId = 6;
                    $status = '';
                    $message = null;
                    $type = null;

                    //return new Response(Response::HTTP_BAD_REQUEST);
                }
            }

            $em = $this->getDoctrine()->getManager();
            $dateTime = new \DateTime();

            if($personId < 6) {
                $status = "CHANGE";
                $Repo = $this->getDoctrine()->getRepository('BrzozowskiIntelliHomeBundle:Persons');
                $person = $Repo->findOneBy(
                    array('id' => $personId)
                );
                $name = $person->getName();
                $message = "Użytkownik ".$name." aktywował alarm przy użyciu swojej karty";
            }

            // Save alarm status
            $alarm = new Alarm();
            $alarm->setDate($dateTime);
            $alarm->setTime($dateTime);
            $alarm->setWho($personId);
            $alarm->setStatus($status);
            $em->persist($alarm);
            $em->flush();

            // Save log
            if($message) {
                $log = new Logs();
                $log->setDate($dateTime)->setTime($dateTime)->setContent($message);
                $em = $this->getDoctrine()->getManager();
                $em->persist($log);
                $em->flush();
            }

            // Save notif
            if($type) {
                $notif = new Notifications($type, $message);
                $em->persist($notif);
                $em->flush();
            }

            if($alarmStatus == 'b') {
                $Repo = $this->getDoctrine()->getRepository('BrzozowskiIntelliHomeBundle:Settings');
                $settingsRow = $Repo->findOneBy(
                    array('id' => 1)
                );
                $phone = $settingsRow->getAlarmPhoneNumber();

                $sms = new SendSMS($this->getParameter('smsapi_token'));
                $result = $sms->sendSMS($phone, 'Włamanie na Lawendowej 46!!!');

                if($result) $message = "Wiadomość SMS o włamaniu została wysłana na: ".$phone;
                else $message = "Wystąpił błąd podczas wysyłania wiadomości SMS (".$sms->getErrorMessage().").";

                $em = $this->getDoctrine()->getManager();
                $dateTime = new \DateTime();

                // Save log
                $log = new Logs();
                $log->setDate($dateTime)->setTime($dateTime)->setContent($message);
                $em->persist($log);
                $em->flush();
            }

            return new Response(Response::HTTP_OK);
        }

        return new Response(Response::HTTP_BAD_REQUEST);
    }


{'fraction_non_alphanumeric': 0.1258682382656283, 'fraction_numerical': 0.002420543043569775, 'mean_word_length': 1.2577809455927773, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 67, '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': '2500142', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2528, 'n_words': 464}