Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 53 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Authority | |
0.00% |
0 / 53 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
setupMapping | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
2 | |||
preSetupFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
preSetup | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
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 | class Authority extends Base |
6 | { |
7 | protected $fieldMapping = [ |
8 | 'id' => 'id', |
9 | 'name' => 'name', |
10 | 'parent_id' => 'parent_id', |
11 | 'meta.locale' => 'locale', |
12 | 'locations' => 'locations_json', |
13 | 'relation' => 'relation_json', |
14 | 'contact' => 'contact_json', |
15 | '__RAW__' => 'data_json' |
16 | ]; |
17 | |
18 | protected function setupMapping() |
19 | { |
20 | $this->referanceMapping = [ |
21 | 'meta' => [ |
22 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Meta', |
23 | 'neededFields' => [ |
24 | 'id' => 'object_id', |
25 | 'meta.locale' => 'locale' |
26 | ], |
27 | 'addFields' => [ |
28 | 'type' => static::getTableName() |
29 | ], |
30 | 'deleteFields' => [ |
31 | 'object_id' => $this->get('id'), |
32 | 'locale' => $this->get('meta.locale'), |
33 | 'type' => static::getTableName() |
34 | ], |
35 | 'clearFields' => ['type' => static::getTableName(), 'locale' => $this->get('meta.locale')], |
36 | 'multiple' => false |
37 | ], |
38 | 'locations' => [ |
39 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\AuthorityLocation', |
40 | 'neededFields' => ['id' => 'authority_id', 'meta.locale' => 'locale'], |
41 | 'addFields' => [ |
42 | |
43 | ], |
44 | 'deleteFields' => [ |
45 | 'authority_id' => $this->get('id'), |
46 | 'locale' => $this->get('meta.locale') |
47 | ], |
48 | 'clearFields' => [ |
49 | 'locale' => $this->get('meta.locale') |
50 | ] |
51 | ], |
52 | ]; |
53 | } |
54 | |
55 | public function preSetupFields() |
56 | { |
57 | $this->dataRaw['parent_id'] = ($this->dataRaw['parent_id'] ?? 0); |
58 | } |
59 | |
60 | public function preSetup() |
61 | { |
62 | try { |
63 | $fields = $this->get(['id', 'meta.locale', 'meta.hash']); |
64 | $fields[] = static::getTableName(); |
65 | $this->setStatus(static::STATUS_OLD); |
66 | if ($this->itemNeedsUpdate(...array_values($fields))) { |
67 | $this->setStatus(static::STATUS_NEW); |
68 | $this->setupFields(); |
69 | $this->deleteEntity(); |
70 | $this->deleteReferences(); |
71 | } |
72 | } catch (\Exception $e) { |
73 | throw $e; |
74 | } |
75 | } |
76 | |
77 | public function deleteEntity(): bool |
78 | { |
79 | try { |
80 | return $this->deleteWith( |
81 | array_combine(['id', 'locale'], array_values($this->get(['id', 'meta.locale']))) |
82 | ); |
83 | } catch (\Exception $e) { |
84 | throw $e; |
85 | } |
86 | } |
87 | |
88 | public function clearEntity(array $addWhere = []): bool |
89 | { |
90 | try { |
91 | return $this->deleteWith( |
92 | ['locale' => $this->get('meta.locale')] |
93 | ); |
94 | } catch (\Exception $e) { |
95 | throw $e; |
96 | } |
97 | } |
98 | } |