|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
|
4
|
|
|
|
|
5
|
|
|
use ControleOnline\Entity\ExtraData; |
|
6
|
|
|
use ControleOnline\Entity\ExtraFields; |
|
7
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
8
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
|
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
class ExtraDataService |
|
16
|
|
|
{ |
|
17
|
|
|
private static $persisted = false; |
|
18
|
|
|
private $request; |
|
19
|
|
|
public function __construct( |
|
20
|
|
|
private EntityManagerInterface $manager, |
|
21
|
|
|
RequestStack $requestStack |
|
22
|
|
|
) { |
|
23
|
|
|
$this->request = $requestStack->getCurrentRequest(); |
|
24
|
|
|
} |
|
25
|
|
|
public function persist($entity) |
|
26
|
|
|
{ |
|
27
|
|
|
if (self::$persisted == true) |
|
|
|
|
|
|
28
|
|
|
return; |
|
29
|
|
|
self::$persisted = true; |
|
30
|
|
|
$this->manager->persist($entity); |
|
31
|
|
|
$this->manager->flush(); |
|
32
|
|
|
$this->persistData( |
|
33
|
|
|
$entity->getId(), |
|
34
|
|
|
(new \ReflectionClass($entity::class))->getShortName() |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
public function persistData($entity_id, $entity_name) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!$entity_id || !$entity_name) |
|
40
|
|
|
return; |
|
41
|
|
|
$extra_data = json_decode($this->request->getContent(), true)['extra-data'] ?? null; |
|
42
|
|
|
if (!$extra_data) |
|
43
|
|
|
return; |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
foreach ($extra_data['data'] as $key => $data) { |
|
47
|
|
|
$extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
|
48
|
|
|
|
|
49
|
|
|
$extraData = $this->manager->getRepository(ExtraData::class)->findOneBy([ |
|
50
|
|
|
'entity_id' => $entity_id, |
|
51
|
|
|
'entity_name' => $entity_name, |
|
52
|
|
|
'extra_fields' => $extra_fields |
|
53
|
|
|
]); |
|
54
|
|
|
|
|
55
|
|
|
if (!$extraData) |
|
56
|
|
|
$extraData = new ExtraData(); |
|
57
|
|
|
|
|
58
|
|
|
$extraData->setExtraFields($extra_fields); |
|
59
|
|
|
$extraData->setEntityName($entity_name); |
|
60
|
|
|
$extraData->setEntityId($entity_id); |
|
61
|
|
|
$extraData->setValue($data); |
|
62
|
|
|
$this->manager->persist($extraData); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$this->manager->flush(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function noChange() |
|
70
|
|
|
{ |
|
71
|
|
|
if (self::$persisted == true) |
|
|
|
|
|
|
72
|
|
|
return; |
|
73
|
|
|
self::$persisted = true; |
|
74
|
|
|
|
|
75
|
|
|
$extra_data = json_decode($this->request->getContent(), true)['extra-data'] ?? null; |
|
76
|
|
|
if (!$extra_data) |
|
77
|
|
|
return; |
|
78
|
|
|
|
|
79
|
|
|
$this->persistData($extra_data['entity_id'], $extra_data['entity_name']); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
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