Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 160 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Topic | |
0.00% |
0 / 160 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
setupMapping | |
0.00% |
0 / 131 |
|
0.00% |
0 / 1 |
2 | |||
deleteReferencesFn | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
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 Topic extends Base |
6 | { |
7 | protected $fieldMapping = [ |
8 | 'id' => 'id', |
9 | 'name' => 'name', |
10 | 'meta.locale' => 'locale', |
11 | 'path' => 'path', |
12 | 'relation.navi' => 'navi', |
13 | 'relation.root' => 'root', |
14 | 'relation.rank' => 'rank', |
15 | '__RAW__' => 'data_json' |
16 | ]; |
17 | |
18 | /** |
19 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
20 | */ |
21 | protected function setupMapping() |
22 | { |
23 | $this->referanceMapping = [ |
24 | 'meta' => [ |
25 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Meta', |
26 | 'neededFields' => [ |
27 | 'id' => 'object_id', |
28 | 'meta.locale' => 'locale' |
29 | ], |
30 | 'addFields' => [ |
31 | 'type' => static::getTableName() |
32 | ], |
33 | 'deleteFields' => [ |
34 | 'object_id' => $this->get('id'), |
35 | 'locale' => $this->get('meta.locale'), |
36 | 'type' => static::getTableName() |
37 | ], |
38 | 'multiple' => false, |
39 | 'clearFields' => [ |
40 | 'type' => static::getTableName(), |
41 | 'locale' => $this->get('meta.locale') |
42 | ], |
43 | ], |
44 | 'name' => [ |
45 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
46 | 'neededFields' => [ |
47 | 'id' => 'object_id', |
48 | 'meta.locale' => 'locale', |
49 | 'name' => 'search_value' |
50 | ], |
51 | 'addFields' => [ |
52 | 'entity_type' => static::getTableName(), |
53 | 'search_type' => 'name' |
54 | ], |
55 | 'multiple' => false, |
56 | 'clearFields' => [ |
57 | 'entity_type' => static::getTableName(), |
58 | 'locale' => $this->get('meta.locale') |
59 | ], |
60 | 'deleteFields' => [ |
61 | 'object_id' => $this->get('id'), |
62 | 'locale' => $this->get('meta.locale'), |
63 | 'entity_type' => static::getTableName() |
64 | ], |
65 | 'selfAsArray' => true |
66 | ], |
67 | 'meta.keywords' => [ |
68 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
69 | 'neededFields' => [ |
70 | 'id' => 'object_id', |
71 | 'meta.locale' => 'locale', |
72 | 'meta.keywords' => 'search_value', |
73 | ], |
74 | 'addFields' => [ |
75 | 'entity_type' => static::getTableName(), |
76 | 'search_type' => 'keywords' |
77 | ], |
78 | 'deleteFields' => [ |
79 | 'object_id' => $this->get('id'), |
80 | 'locale' => $this->get('meta.locale'), |
81 | 'entity_type' => static::getTableName() |
82 | ], |
83 | 'multiple' => false, |
84 | 'clearFields' => [ |
85 | 'entity_type' => static::getTableName(), |
86 | 'locale' => $this->get('meta.locale') |
87 | ], |
88 | 'selfAsArray' => true |
89 | ], |
90 | 'meta.titles' => [ |
91 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
92 | 'neededFields' => [ |
93 | 'id' => 'object_id', |
94 | 'meta.locale' => 'locale', |
95 | 'meta.titles' => 'search_value' |
96 | ], |
97 | 'addFields' => [ |
98 | 'entity_type' => static::getTableName(), |
99 | 'search_type' => 'titles' |
100 | ], |
101 | 'deleteFields' => [ |
102 | 'object_id' => $this->get('id'), |
103 | 'locale' => $this->get('locale'), |
104 | 'entity_type' => static::getTableName() |
105 | ], |
106 | 'multiple' => false, |
107 | 'clearFields' => [ |
108 | 'entity_type' => static::getTableName(), |
109 | 'locale' => $this->get('locale') |
110 | ], |
111 | 'selfAsArray' => true |
112 | ], |
113 | 'links' => [ |
114 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\TopicLinks', |
115 | 'neededFields' => ['id' => 'topic_id', 'meta.locale' => 'locale'], |
116 | 'addFields' => ['locale' => $this->get('meta.locale')], |
117 | 'delete' => false, |
118 | 'deleteFunction' => function (\BO\Zmsdldb\Importer\MySQL\Entity\Topic $topic) { |
119 | return static::deleteReferencesFn( |
120 | $topic, |
121 | \BO\Zmsdldb\Importer\MySQL\Entity\TopicLinks::getTableName(), |
122 | 'topic_id' |
123 | ); |
124 | }, |
125 | 'clearFields' => [ |
126 | 'locale' => $this->get('meta.locale') |
127 | ] |
128 | ], |
129 | 'relation.services' => [ |
130 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\TopicService', |
131 | 'neededFields' => ['id' => 'topic_id'], |
132 | 'addFields' => [], |
133 | 'deleteFunction' => function (\BO\Zmsdldb\Importer\MySQL\Entity\Topic $topic) { |
134 | return static::deleteReferencesFn( |
135 | $topic, |
136 | \BO\Zmsdldb\Importer\MySQL\Entity\TopicService::getTableName(), |
137 | 'topic_id' |
138 | ); |
139 | } |
140 | ], |
141 | 'relation.childs' => [ |
142 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\TopicCluster', |
143 | 'neededFields' => ['id' => 'parent_id'], |
144 | 'addFields' => [], |
145 | 'deleteFunction' => function (\BO\Zmsdldb\Importer\MySQL\Entity\Topic $topic) { |
146 | return static::deleteReferencesFn( |
147 | $topic, |
148 | \BO\Zmsdldb\Importer\MySQL\Entity\TopicCluster::getTableName(), |
149 | 'parent_id' |
150 | ); |
151 | } |
152 | ] |
153 | ]; |
154 | } |
155 | |
156 | protected static function deleteReferencesFn( |
157 | \BO\Zmsdldb\Importer\MySQL\Entity\Topic $topic, |
158 | string $tableName, |
159 | string $whereField |
160 | ) { |
161 | $topicId = $topic->get('id'); |
162 | try { |
163 | $sql = "DELETE FROM " . $tableName . " WHERE " . $whereField . " = ?"; |
164 | $stm = $topic->getPDOAccess()->prepare($sql); |
165 | |
166 | $stm->execute([$topicId]); |
167 | if ($stm && 0 < $stm->rowCount()) { |
168 | return true; |
169 | } |
170 | return false; |
171 | } catch (\Exception $e) { |
172 | throw $e; |
173 | } |
174 | } |
175 | |
176 | public function preSetup() |
177 | { |
178 | try { |
179 | $fields = $this->get(['id', 'meta.locale', 'meta.hash']); |
180 | $fields[] = static::getTableName(); |
181 | $this->setStatus(static::STATUS_OLD); |
182 | if ($this->itemNeedsUpdate(...array_values($fields))) { |
183 | $this->setStatus(static::STATUS_NEW); |
184 | $this->setupFields(); |
185 | $this->deleteEntity(); |
186 | $this->deleteReferences(); |
187 | } |
188 | } catch (\Exception $e) { |
189 | throw $e; |
190 | } |
191 | } |
192 | |
193 | public function deleteEntity(): bool |
194 | { |
195 | try { |
196 | return $this->deleteWith( |
197 | array_combine(['id', 'locale'], array_values($this->get(['id', 'meta.locale']))) |
198 | ); |
199 | } catch (\Exception $e) { |
200 | throw $e; |
201 | } |
202 | } |
203 | |
204 | public function clearEntity(array $addWhere = []): bool |
205 | { |
206 | try { |
207 | return $this->deleteWith( |
208 | ['locale' => $this->get('meta.locale')] |
209 | ); |
210 | } catch (\Exception $e) { |
211 | throw $e; |
212 | } |
213 | } |
214 | } |