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