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