Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 226 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Service | |
0.00% |
0 / 226 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
setupMapping | |
0.00% |
0 / 204 |
|
0.00% |
0 / 1 |
2 | |||
preSetup | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
deleteEntity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
clearEntity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdldb\Importer\MySQL\Entity; |
4 | |
5 | use Error; |
6 | |
7 | class Service extends Base |
8 | { |
9 | protected $fieldMapping = [ |
10 | 'id' => 'id', |
11 | 'name' => 'name', |
12 | 'hint' => 'hint', |
13 | 'leika' => 'leika', |
14 | 'fees' => 'fees', |
15 | 'appointment.link' => 'appointment_all_link', |
16 | 'responsibility' => 'responsibility', |
17 | 'responsibility_all' => 'responsibility_all', |
18 | 'description' => 'description', |
19 | 'processing_time' => 'processing_time', |
20 | 'relation.root_topic' => 'root_topic_id', |
21 | 'meta.locale' => 'locale', |
22 | 'residence' => 'residence', |
23 | 'representation' => 'representation', |
24 | 'authorities' => 'authorities_json', |
25 | 'onlineprocessing' => 'onlineprocessing_json', |
26 | 'relation' => 'relation_json', |
27 | '__RAW__' => 'data_json' |
28 | ]; |
29 | |
30 | /** |
31 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
32 | */ |
33 | protected function setupMapping() |
34 | { |
35 | $this->referanceMapping = [ |
36 | 'name' => [ |
37 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
38 | 'neededFields' => [ |
39 | 'id' => 'object_id', |
40 | 'meta.locale' => 'locale', |
41 | 'name' => 'search_value' |
42 | ], |
43 | 'addFields' => [ |
44 | 'entity_type' => static::getTableName(), |
45 | 'search_type' => 'name' |
46 | ], |
47 | 'multiple' => false, |
48 | 'clearFields' => [ |
49 | 'entity_type' => static::getTableName(), |
50 | 'locale' => $this->get('meta.locale') |
51 | ], |
52 | 'deleteFields' => [ |
53 | 'object_id' => $this->get('id'), |
54 | 'locale' => $this->get('meta.locale'), |
55 | 'entity_type' => static::getTableName() |
56 | ], |
57 | 'selfAsArray' => true |
58 | ], |
59 | /* |
60 | 'description' => [ |
61 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
62 | 'neededFields' => [ |
63 | 'id' => 'object_id', |
64 | 'meta.locale' => 'locale', |
65 | 'description' => 'search_value' |
66 | ], |
67 | 'addFields' => [ |
68 | 'entity_type' => static::getTableName(), |
69 | 'search_type' => 'description' |
70 | ], |
71 | 'deleteFields' => [ |
72 | 'object_id' => $this->get('id'), |
73 | 'locale' => $this->get('meta.locale'), |
74 | 'entity_type' => static::getTableName() |
75 | ], |
76 | 'multiple' => false, |
77 | 'clearFields' => [ |
78 | 'entity_type' => static::getTableName(), |
79 | 'locale' => $this->get('meta.locale') |
80 | ], |
81 | 'selfAsArray' => true |
82 | ], |
83 | */ |
84 | 'meta.keywords' => [ |
85 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
86 | 'neededFields' => [ |
87 | 'id' => 'object_id', |
88 | 'meta.locale' => 'locale', |
89 | 'meta.keywords' => 'search_value', |
90 | ], |
91 | 'addFields' => [ |
92 | 'entity_type' => static::getTableName(), |
93 | 'search_type' => 'keywords' |
94 | ], |
95 | 'deleteFields' => [ |
96 | 'object_id' => $this->get('id'), |
97 | 'locale' => $this->get('meta.locale'), |
98 | 'entity_type' => static::getTableName() |
99 | ], |
100 | 'multiple' => false, |
101 | 'clearFields' => [ |
102 | 'entity_type' => static::getTableName(), |
103 | 'locale' => $this->get('meta.locale') |
104 | ], |
105 | 'selfAsArray' => true |
106 | ], |
107 | 'meta' => [ |
108 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Meta', |
109 | 'neededFields' => ['id' => 'object_id', 'meta.locale' => 'locale'], |
110 | 'addFields' => [ |
111 | 'type' => static::getTableName() |
112 | ], |
113 | 'deleteFields' => [ |
114 | 'object_id' => $this->get('id'), |
115 | 'locale' => $this->get('meta.locale'), |
116 | 'type' => static::getTableName() |
117 | ], |
118 | 'multiple' => false, |
119 | 'clearFields' => [ |
120 | 'type' => static::getTableName(), |
121 | 'locale' => $this->get('meta.locale') |
122 | ], |
123 | ], |
124 | 'authorities' => [ |
125 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\AuthorityService', |
126 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
127 | 'addFields' => [ |
128 | |
129 | ], |
130 | 'deleteFields' => [ |
131 | 'service_id' => $this->get('id'), |
132 | 'locale' => $this->get('meta.locale') |
133 | ], |
134 | 'clearFields' => [ |
135 | 'locale' => $this->get('meta.locale') |
136 | ] |
137 | ], |
138 | 'locations' => [ |
139 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\LocationService', |
140 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
141 | 'addFields' => [], |
142 | 'deleteFields' => [ |
143 | 'service_id' => $this->get('id'), |
144 | 'locale' => $this->get('meta.locale') |
145 | ], |
146 | 'clearFields' => [ |
147 | 'locale' => $this->get('meta.locale') |
148 | ] |
149 | ], |
150 | 'requirements' => [ |
151 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\ServiceInformation', |
152 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
153 | 'addFields' => [ |
154 | 'type' => 'requirements', |
155 | 'sort' => function ($position, $key, $value) { |
156 | return $position; |
157 | } |
158 | ], |
159 | 'deleteFields' => [ |
160 | 'service_id' => $this->get('id'), |
161 | 'locale' => $this->get('meta.locale'), |
162 | 'type' => 'requirements', |
163 | ], |
164 | 'clearFields' => [ |
165 | 'type' => 'requirements', |
166 | 'locale' => $this->get('meta.locale') |
167 | ], |
168 | ], |
169 | 'forms' => [ |
170 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\ServiceInformation', |
171 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
172 | 'addFields' => [ |
173 | 'type' => 'forms', |
174 | 'sort' => function ($position, $key, $value) { |
175 | return $position; |
176 | } |
177 | ], |
178 | 'deleteFields' => [ |
179 | 'service_id' => $this->get('id'), |
180 | 'locale' => $this->get('meta.locale'), |
181 | 'type' => 'forms', |
182 | ], |
183 | 'clearFields' => [ |
184 | 'type' => 'forms', |
185 | 'locale' => $this->get('meta.locale') |
186 | ], |
187 | ], |
188 | 'prerequisites' => [ |
189 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\ServiceInformation', |
190 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
191 | 'addFields' => [ |
192 | 'type' => 'prerequisites', |
193 | 'sort' => function ($position, $key, $value) { |
194 | return $position; |
195 | } |
196 | ], |
197 | 'deleteFields' => [ |
198 | 'service_id' => $this->get('id'), |
199 | 'locale' => $this->get('meta.locale'), |
200 | 'type' => 'prerequisites', |
201 | ], |
202 | 'clearFields' => [ |
203 | 'type' => 'prerequisites', |
204 | 'locale' => $this->get('meta.locale') |
205 | ], |
206 | ], |
207 | 'links' => [ |
208 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\ServiceInformation', |
209 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
210 | 'addFields' => [ |
211 | 'type' => 'links', |
212 | 'sort' => function ($position, $key, $value) { |
213 | return $position; |
214 | } |
215 | ], |
216 | 'deleteFields' => [ |
217 | 'service_id' => $this->get('id'), |
218 | 'locale' => $this->get('meta.locale'), |
219 | 'type' => 'links', |
220 | ], |
221 | 'clearFields' => [ |
222 | 'type' => 'links', |
223 | 'locale' => $this->get('meta.locale') |
224 | ], |
225 | ], |
226 | 'publications' => [ |
227 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\ServiceInformation', |
228 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
229 | 'addFields' => [ |
230 | 'type' => 'publications', |
231 | 'sort' => function ($position, $key, $value) { |
232 | return $position; |
233 | } |
234 | ], |
235 | 'deleteFields' => [ |
236 | 'service_id' => $this->get('id'), |
237 | 'locale' => $this->get('meta.locale'), |
238 | 'type' => 'publications', |
239 | ], |
240 | 'clearFields' => [ |
241 | 'type' => 'publications', |
242 | 'locale' => $this->get('meta.locale') |
243 | ], |
244 | ], |
245 | 'legal' => [ |
246 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\ServiceInformation', |
247 | 'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'], |
248 | 'addFields' => [ |
249 | 'type' => 'legal', |
250 | 'sort' => function ($position, $key, $value) { |
251 | return $position; |
252 | } |
253 | ], |
254 | 'deleteFields' => [ |
255 | 'service_id' => $this->get('id'), |
256 | 'locale' => $this->get('meta.locale'), |
257 | 'type' => 'legal', |
258 | ], |
259 | 'clearFields' => [ |
260 | 'type' => 'legal', |
261 | 'locale' => $this->get('meta.locale') |
262 | ], |
263 | ] |
264 | ]; |
265 | } |
266 | |
267 | public function preSetup() |
268 | { |
269 | try { |
270 | /* |
271 | if (false === $this->get('meta.translated')) { |
272 | $this->setStatus(static::STATUS_OLD); |
273 | error_log( |
274 | 'not translated service - (' . $this->get('id') . ' | ' . |
275 | $this->get('meta.locale') . ') - ' . $this->get('name') |
276 | ); |
277 | return false; |
278 | } |
279 | else { |
280 | error_log( |
281 | 'translated service - (' . $this->get('id') . ' | ' . |
282 | $this->get('meta.locale') . ') - ' . $this->get('name') |
283 | ); |
284 | } |
285 | */ |
286 | $fields = $this->get(['id', 'meta.locale', 'meta.hash']); |
287 | $fields[] = static::getTableName(); |
288 | |
289 | if (is_array($fields[2])) { |
290 | error_log(print_r($fields[2])); |
291 | } |
292 | #error_log(print_r($fields[2])); |
293 | |
294 | $this->setStatus(static::STATUS_OLD); |
295 | if ($this->itemNeedsUpdate(...array_values($fields))) { |
296 | $this->setStatus(static::STATUS_NEW); |
297 | $this->setupFields(); |
298 | $this->deleteEntity(); |
299 | $this->deleteReferences(); |
300 | } |
301 | } catch (\Exception $e) { |
302 | throw $e; |
303 | } |
304 | } |
305 | |
306 | public function deleteEntity(): bool |
307 | { |
308 | try { |
309 | return $this->deleteWith( |
310 | array_combine(['id', 'locale'], array_values($this->get(['id', 'meta.locale']))) |
311 | ); |
312 | } catch (\Exception $e) { |
313 | throw $e; |
314 | } |
315 | } |
316 | |
317 | public function clearEntity(array $addWhere = []): bool |
318 | { |
319 | try { |
320 | #print_r((array)$this->get(['meta.locale']));exit; |
321 | return $this->deleteWith( |
322 | ['locale' => $this->get('meta.locale')] |
323 | ); |
324 | } catch (\Exception $e) { |
325 | throw $e; |
326 | } |
327 | } |
328 | } |