1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
6
|
|
|
use ControleOnline\Entity\Task; |
7
|
|
|
use ControleOnline\Entity\TaskInteration; |
8
|
|
|
use ControleOnline\Messages\MessageInterface; |
|
|
|
|
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
10
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface as Security; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class TaskInterationService |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function __construct( |
16
|
|
|
private EntityManagerInterface $manager, |
17
|
|
|
private Security $security, |
18
|
|
|
private StatusService $statusService, |
|
|
|
|
19
|
|
|
private PeopleService $peopleService, |
|
|
|
|
20
|
|
|
private FileService $fileService |
|
|
|
|
21
|
|
|
) {} |
22
|
|
|
|
23
|
|
|
public function addClientInteration(MessageInterface $message, People $provider, string $type): TaskInteration |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
$number = preg_replace('/\D/', '', $message->getOriginNumber()); |
27
|
|
|
$name = ''; |
28
|
|
|
$phone = [ |
29
|
|
|
'ddi' => substr($number, 0, 2), |
30
|
|
|
'ddd' => substr($number, 2, 2), |
31
|
|
|
'phone' => substr($number, 4) |
32
|
|
|
]; |
33
|
|
|
$registredBy = $this->peopleService->discoveryPeople(null, null, $phone, $name, null); |
34
|
|
|
$task = $this->discoveryOpenTask($provider, $registredBy, $type); |
35
|
|
|
return $this->addInteration($registredBy, $message, $task, $type, 'public'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function addInteration(People $registredBy, MessageInterface $message, Task $task, string $type, ?string $visibility = 'private') |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
$file = null; |
42
|
|
|
$media = $message->getMessageContent()->getMedia(); |
43
|
|
|
if ($media) |
44
|
|
|
$file = $this->fileService->addFile( |
45
|
|
|
$registredBy, |
46
|
|
|
pack("C*", ...$media->getData()), |
47
|
|
|
$type |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$taskInteration = new TaskInteration(); |
51
|
|
|
$taskInteration->setTask($task); |
52
|
|
|
$taskInteration->settype($type); |
53
|
|
|
$taskInteration->setVisibility($visibility); |
54
|
|
|
$taskInteration->setBody($message->getMessageContent()->getBody()); |
55
|
|
|
$taskInteration->setRegisteredBy($registredBy); |
56
|
|
|
if ($file) |
57
|
|
|
$taskInteration->setFile($file); |
58
|
|
|
|
59
|
|
|
$this->manager->persist($taskInteration); |
60
|
|
|
$this->manager->flush(); |
61
|
|
|
|
62
|
|
|
return $taskInteration; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function discoveryOpenTask(People $provider, People $registredBy, string $type): Task |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
$openStatus = $this->statusService->discoveryStatus('open', 'open', $type); |
69
|
|
|
$pendingStatus = $this->statusService->discoveryStatus('pending', 'pending', $type); |
70
|
|
|
|
71
|
|
|
$task = $this->manager->getRepository(Task::class)->findOneBy([ |
72
|
|
|
'status' => [$openStatus, $pendingStatus], |
73
|
|
|
'provider' => $provider, |
74
|
|
|
'registredBy' => $registredBy, |
75
|
|
|
'type' => $type |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
if (!$task) { |
79
|
|
|
$task = new Task(); |
80
|
|
|
$task->setRegisteredBy($registredBy); |
81
|
|
|
$task->setProvider($provider); |
82
|
|
|
$task->settype($type); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$task->setTaskStatus($openStatus); |
86
|
|
|
$this->manager->persist($task); |
87
|
|
|
$this->manager->flush(); |
88
|
|
|
|
89
|
|
|
return $task; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function prePersist(TaskInteration $taskInteration): TaskInteration |
93
|
|
|
{ |
94
|
|
|
if (!$taskInteration->getRegisteredBy()) |
95
|
|
|
$taskInteration->setRegisteredBy($this->security->getToken()->getUser()->getPeople()); |
96
|
|
|
return $taskInteration; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths