Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
TopicLinks | |
0.00% |
0 / 29 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
postSetupFields | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
clearEntity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
deleteEntity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
postSave | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdldb\Importer\MySQL\Entity; |
4 | |
5 | class TopicLinks extends Base |
6 | { |
7 | protected $fieldMapping = [ |
8 | 'topic_id' => 'topic_id', |
9 | 'name' => 'name', |
10 | 'locale' => 'locale', |
11 | 'rank' => 'rank', |
12 | 'link' => 'url', |
13 | 'search' => 'search', |
14 | 'highlight' => 'highlight', |
15 | #'meta.keywords' => 'keywords', |
16 | #'meta.titles' => 'titles', |
17 | 'meta' => 'meta_json', |
18 | '__RAW__' => 'data_json' |
19 | ]; |
20 | |
21 | public function postSetupFields() |
22 | { |
23 | $searchValues = [$this->get('name')]; |
24 | /* |
25 | if (array_key_exists('titles', ($this->fields['meta'] ?? [])) && !empty($this->fields['meta']['titles'])) { |
26 | $titels = $this->fields['meta']['titles']; |
27 | if (is_string($this->fields['meta']['titles'])) { |
28 | $titels = explode(',', $this->fields['meta']['titles']); |
29 | } |
30 | $titels = array_filter($titels); |
31 | array_push($searchValues, ...$titels); |
32 | } |
33 | */ |
34 | |
35 | $keywords = $this->get('meta.keywords'); |
36 | if (!empty($keywords)) { |
37 | if (is_string($keywords)) { |
38 | $keywords = explode(',', $keywords); |
39 | } |
40 | $keywords = array_filter($keywords); |
41 | array_push($searchValues, ...$keywords); |
42 | } |
43 | |
44 | $this->fields['search'] = implode(', ', $searchValues); |
45 | } |
46 | |
47 | public function clearEntity(array $addWhere = []): bool |
48 | { |
49 | try { |
50 | return $this->deleteWith( |
51 | ['locale' => $this->get('meta.locale')] |
52 | ); |
53 | } catch (\Exception $e) { |
54 | throw $e; |
55 | } |
56 | } |
57 | |
58 | public function deleteEntity(): bool |
59 | { |
60 | try { |
61 | return $this->deleteWith( |
62 | array_combine(['topic_id', 'locale'], array_values($this->get('topic_id', 'locale'))) |
63 | ); |
64 | } catch (\Exception $e) { |
65 | throw $e; |
66 | } |
67 | } |
68 | |
69 | public function postSave(\PDOStatement $stm, Base $entity) |
70 | { |
71 | return true; |
72 | try { |
73 | if ($stm && 0 < $stm->rowCount()) { |
74 | #$lastInsertId = $pdoConnection->lastInsertId(); |
75 | |
76 | $sql = 'REPLACE INTO ' . static::getTableName() . ' '; |
77 | $sql .= '(`' . implode('`, `', array_keys($this->fields)) . '`) '; |
78 | |
79 | $questionMarks = array_fill(0, count($this->fields), '?'); |
80 | $sql .= 'VALUES (' . implode(', ', $questionMarks) . ') '; |
81 | |
82 | #print_r($sql . \PHP_EOL) ; |
83 | $stm = $this->getPDOAccess()->prepare($sql); |
84 | |
85 | $stm->execute(array_values($this->fields)); |
86 | |
87 | return true; |
88 | } |
89 | } catch (\Exception $e) { |
90 | throw $e; |
91 | } |
92 | } |
93 | } |