@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $class = $this->getEntityName($entity); |
| 49 | 49 | |
| 50 | - $extraData = $this->getEntityByExtraData($extraFields, $entityId, $entity, $code); |
|
| 50 | + $extraData = $this->getEntityByExtraData($extraFields, $entityId, $entity, $code); |
|
| 51 | 51 | if ($extraData) return $extraData; |
| 52 | 52 | |
| 53 | 53 | $extraData = new ExtraData(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
| 64 | + public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
| 65 | 65 | { |
| 66 | 66 | |
| 67 | 67 | $extraFields = $this->manager->getRepository(ExtraFields::class)->findOneBy([ |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | //$this->manager->persist($entity); |
| 139 | 139 | } else { |
| 140 | - $json = json_decode($this->request->getContent(), true); |
|
| 140 | + $json = json_decode($this->request->getContent(), true); |
|
| 141 | 141 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
| 142 | 142 | if (!$extra_data) |
| 143 | 143 | return; |
@@ -36,8 +36,9 @@ discard block |
||
| 36 | 36 | 'entity_id' => $entityId, |
| 37 | 37 | 'value' => $code |
| 38 | 38 | ]); |
| 39 | - if ($extraData) |
|
| 40 | - return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
|
| 39 | + if ($extraData) { |
|
| 40 | + return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | 43 | return null; |
| 43 | 44 | } |
@@ -48,7 +49,9 @@ discard block |
||
| 48 | 49 | $class = $this->getEntityName($entity); |
| 49 | 50 | |
| 50 | 51 | $extraData = $this->getEntityByExtraData($extraFields, $entityId, $entity, $code); |
| 51 | - if ($extraData) return $extraData; |
|
| 52 | + if ($extraData) { |
|
| 53 | + return $extraData; |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | $extraData = new ExtraData(); |
| 54 | 57 | $extraData->setEntityId($entityId); |
@@ -70,8 +73,9 @@ discard block |
||
| 70 | 73 | 'context' => $context |
| 71 | 74 | ]); |
| 72 | 75 | |
| 73 | - if (!$extraFields) |
|
| 74 | - $extraFields = new ExtraFields(); |
|
| 76 | + if (!$extraFields) { |
|
| 77 | + $extraFields = new ExtraFields(); |
|
| 78 | + } |
|
| 75 | 79 | |
| 76 | 80 | $extraFields->setName($fieldName); |
| 77 | 81 | $extraFields->setContext($context); |
@@ -92,12 +96,15 @@ discard block |
||
| 92 | 96 | |
| 93 | 97 | public function discoveryDevice(&$entity) |
| 94 | 98 | { |
| 95 | - if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) |
|
| 96 | - return; |
|
| 99 | + if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 97 | 102 | |
| 98 | 103 | $deviceId = $this->request->headers->get('DEVICE') ?: $this->getUserIp(); |
| 99 | 104 | if (method_exists($entity, 'setDevice')) { |
| 100 | - if ($entity->getDevice()) return; |
|
| 105 | + if ($entity->getDevice()) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 101 | 108 | $device = $this->deviceService->discoveryDevice($deviceId); |
| 102 | 109 | $entity->setDevice($device); |
| 103 | 110 | } |
@@ -108,14 +115,16 @@ discard block |
||
| 108 | 115 | $token = $this->security->getToken(); |
| 109 | 116 | $user = $token ? $token->getUser() : $this->skyNetService->getBotUser(); |
| 110 | 117 | |
| 111 | - if (method_exists($entity, 'setUser') && !$entity->getUser()) |
|
| 112 | - $entity->setUser($user); |
|
| 118 | + if (method_exists($entity, 'setUser') && !$entity->getUser()) { |
|
| 119 | + $entity->setUser($user); |
|
| 120 | + } |
|
| 113 | 121 | } |
| 114 | 122 | |
| 115 | 123 | public function persist(&$entity) |
| 116 | 124 | { |
| 117 | - if (self::$persisted == true) |
|
| 118 | - return; |
|
| 125 | + if (self::$persisted == true) { |
|
| 126 | + return; |
|
| 127 | + } |
|
| 119 | 128 | self::$persisted = true; |
| 120 | 129 | |
| 121 | 130 | //$this->manager->persist($entity); |
@@ -139,15 +148,17 @@ discard block |
||
| 139 | 148 | } else { |
| 140 | 149 | $json = json_decode($this->request->getContent(), true); |
| 141 | 150 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
| 142 | - if (!$extra_data) |
|
| 143 | - return; |
|
| 151 | + if (!$extra_data) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 144 | 154 | $entity_id = $extra_data['entity_id']; |
| 145 | 155 | $entity_name = $extra_data['entity_name']; |
| 146 | 156 | } |
| 147 | 157 | |
| 148 | 158 | |
| 149 | - if (!$entity_id || !$entity_name) |
|
| 150 | - return; |
|
| 159 | + if (!$entity_id || !$entity_name) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 151 | 162 | |
| 152 | 163 | foreach ($extra_data['data'] as $key => $data) { |
| 153 | 164 | $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
@@ -158,8 +169,9 @@ discard block |
||
| 158 | 169 | 'extra_fields' => $extra_fields |
| 159 | 170 | ]); |
| 160 | 171 | |
| 161 | - if (!$extraData) |
|
| 162 | - $extraData = new ExtraData(); |
|
| 172 | + if (!$extraData) { |
|
| 173 | + $extraData = new ExtraData(); |
|
| 174 | + } |
|
| 163 | 175 | |
| 164 | 176 | $extraData->setExtraFields($extra_fields); |
| 165 | 177 | $extraData->setEntityName($entity_name); |