|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IncidentBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use IncidentBundle\Entity\Incident; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use Exception; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class IncidentHookController |
|
14
|
|
|
*/ |
|
15
|
|
|
class IncidentHookController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/dnnlpwo2cj287189282bbcnjskshewk/{checkIdent}") |
|
19
|
|
|
* |
|
20
|
|
|
* @param Request $request |
|
21
|
|
|
* |
|
22
|
|
|
* @return Response |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function emailReciveCheckProcHookAction($checkIdent, Request $request) |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
1 |
|
$ident = $this->getIdent($checkIdent); |
|
27
|
|
|
|
|
28
|
1 |
|
$errors = []; |
|
29
|
1 |
|
$responseData = []; |
|
30
|
1 |
|
set_error_handler($this->getErrorHandlerCallback($errors)); |
|
31
|
|
|
|
|
32
|
|
|
try { |
|
33
|
1 |
|
$entityManager = $this->getDoctrine()->getManager(); |
|
34
|
1 |
|
if (!$incident = $this->getIncident($ident)) { |
|
35
|
1 |
|
$incident = new Incident($ident); |
|
36
|
1 |
|
$entityManager->persist($incident); |
|
37
|
|
|
} |
|
38
|
1 |
|
$incident->setMessage('Can\'t send&receive email check fail'); |
|
39
|
1 |
|
$incident->setStatus(500); |
|
40
|
1 |
|
$entityManager->flush(); |
|
41
|
|
|
} catch (Exception $e) { |
|
42
|
|
|
$errors[] = $e; |
|
43
|
|
|
} |
|
44
|
1 |
|
$responseData['status'] = empty($errors) ? 'ok' : 'error'; |
|
45
|
|
|
|
|
46
|
1 |
|
return new Response(json_encode($responseData)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $ident |
|
51
|
|
|
* |
|
52
|
|
|
* @return Incident |
|
53
|
|
|
*/ |
|
54
|
1 |
|
protected function getIncident($ident) |
|
55
|
|
|
{ |
|
56
|
1 |
|
$incident = $this->getDoctrine() |
|
57
|
1 |
|
->getRepository('IncidentBundle:Incident') |
|
58
|
1 |
|
->findOneBy(['ident' => $ident], ['id' => 'desc']); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
1 |
|
return $incident; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $errors |
|
65
|
|
|
* |
|
66
|
|
|
* @return \Closure |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getErrorHandlerCallback(&$errors) |
|
69
|
|
|
{ |
|
70
|
1 |
|
return function ($errno, $errstr, $errfile, $errline) use (&$errors) { |
|
|
|
|
|
|
71
|
|
|
$errors[] = ['code' => $errno, 'text' => $errstr]; |
|
72
|
1 |
|
}; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param $checkIdent |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
1 |
|
protected function getIdent($checkIdent) |
|
81
|
|
|
{ |
|
82
|
1 |
|
return sprintf('%s.%s', $checkIdent, date('Ymd')); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.