Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 152 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Location | |
0.00% |
0 / 152 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| setupMapping | |
0.00% |
0 / 128 |
|
0.00% |
0 / 1 |
2 | |||
| preSetupFields | |
0.00% |
0 / 4 |
|
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 Location extends Base |
| 6 | { |
| 7 | protected $fieldMapping = [ |
| 8 | 'id' => 'id', |
| 9 | 'name' => 'name', |
| 10 | 'category.name' => 'category_name', |
| 11 | 'category.identifier' => 'category_identifier', |
| 12 | 'authority.id' => 'authority_id', |
| 13 | 'authority.name' => 'authority_name', |
| 14 | 'meta.locale' => 'locale', |
| 15 | 'note' => 'note', |
| 16 | 'category' => 'category_json', |
| 17 | 'urgent' => 'urgent_json', |
| 18 | 'opening_times' => 'opening_times_json', |
| 19 | 'transit' => 'transit_json', |
| 20 | 'payment_info' => 'payment_json', |
| 21 | 'accessibility' => 'accessibility_json', |
| 22 | 'appointment' => 'appointment_json', |
| 23 | '__RAW__' => 'data_json' |
| 24 | ]; |
| 25 | /** |
| 26 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 27 | */ |
| 28 | protected function setupMapping() |
| 29 | { |
| 30 | $this->referanceMapping = [ |
| 31 | 'name' => [ |
| 32 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
| 33 | 'neededFields' => [ |
| 34 | 'id' => 'object_id', |
| 35 | 'meta.locale' => 'locale', |
| 36 | 'name' => 'search_value' |
| 37 | ], |
| 38 | 'addFields' => [ |
| 39 | 'entity_type' => static::getTableName(), |
| 40 | 'search_type' => 'name' |
| 41 | ], |
| 42 | 'multiple' => false, |
| 43 | 'clearFields' => [ |
| 44 | 'entity_type' => static::getTableName(), |
| 45 | 'locale' => $this->get('meta.locale') |
| 46 | ], |
| 47 | 'deleteFields' => [ |
| 48 | 'object_id' => $this->get('id'), |
| 49 | 'locale' => $this->get('meta.locale'), |
| 50 | 'entity_type' => static::getTableName() |
| 51 | ], |
| 52 | 'selfAsArray' => true |
| 53 | ], |
| 54 | 'address' => [ |
| 55 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
| 56 | 'neededFields' => [ |
| 57 | 'id' => 'object_id', |
| 58 | 'meta.locale' => 'locale', |
| 59 | 'address' => 'search_value', |
| 60 | ], |
| 61 | 'addFields' => [ |
| 62 | 'entity_type' => static::getTableName(), |
| 63 | 'search_type' => 'address' |
| 64 | ], |
| 65 | 'deleteFields' => [ |
| 66 | 'object_id' => $this->get('id'), |
| 67 | 'locale' => $this->get('meta.locale'), |
| 68 | 'entity_type' => static::getTableName() |
| 69 | ], |
| 70 | 'multiple' => false, |
| 71 | 'clearFields' => [ |
| 72 | 'entity_type' => static::getTableName(), |
| 73 | 'locale' => $this->get('meta.locale') |
| 74 | ], |
| 75 | 'selfAsArray' => true |
| 76 | ], |
| 77 | 'meta.keywords' => [ |
| 78 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
| 79 | 'neededFields' => [ |
| 80 | 'id' => 'object_id', |
| 81 | 'meta.locale' => 'locale', |
| 82 | 'meta.keywords' => 'search_value', |
| 83 | ], |
| 84 | 'addFields' => [ |
| 85 | 'entity_type' => static::getTableName(), |
| 86 | 'search_type' => 'keywords' |
| 87 | ], |
| 88 | 'deleteFields' => [ |
| 89 | 'object_id' => $this->get('id'), |
| 90 | 'locale' => $this->get('meta.locale'), |
| 91 | 'entity_type' => static::getTableName() |
| 92 | ], |
| 93 | 'multiple' => false, |
| 94 | 'clearFields' => [ |
| 95 | 'entity_type' => static::getTableName(), |
| 96 | 'locale' => $this->get('meta.locale') |
| 97 | ], |
| 98 | 'selfAsArray' => true |
| 99 | ], |
| 100 | 'meta' => [ |
| 101 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Meta', |
| 102 | 'neededFields' => [ |
| 103 | 'id' => 'object_id', |
| 104 | 'meta.locale' => 'locale' |
| 105 | ], |
| 106 | 'addFields' => [ |
| 107 | 'type' => static::getTableName() |
| 108 | ], |
| 109 | 'deleteFields' => [ |
| 110 | 'object_id' => $this->get('id'), |
| 111 | 'locale' => $this->get('meta.locale'), |
| 112 | 'type' => static::getTableName() |
| 113 | ], |
| 114 | 'multiple' => false, |
| 115 | 'clearFields' => ['type' => static::getTableName(), 'locale' => $this->get('meta.locale')], |
| 116 | ], |
| 117 | 'contact' => [ |
| 118 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Contact', |
| 119 | 'neededFields' => [ |
| 120 | 'id' => 'object_id', |
| 121 | 'meta.locale' => 'locale', |
| 122 | 'address' => 'address', |
| 123 | 'geo' => 'geo' |
| 124 | ], |
| 125 | 'deleteFields' => [ |
| 126 | 'object_id' => $this->get('id'), |
| 127 | 'locale' => $this->get('meta.locale') |
| 128 | ], |
| 129 | 'addFields' => [], |
| 130 | 'multiple' => false, |
| 131 | 'selfAsArray' => true, |
| 132 | 'clearFields' => ['locale' => $this->get('meta.locale')], |
| 133 | ], |
| 134 | 'name' => [ |
| 135 | 'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search', |
| 136 | 'neededFields' => [ |
| 137 | 'id' => 'object_id', |
| 138 | 'meta.locale' => 'locale', |
| 139 | 'name' => 'search_value' |
| 140 | ], |
| 141 | 'addFields' => [ |
| 142 | 'entity_type' => static::getTableName(), |
| 143 | 'search_type' => 'name' |
| 144 | ], |
| 145 | 'deleteFields' => [ |
| 146 | 'object_id' => $this->get('id'), |
| 147 | 'locale' => $this->get('meta.locale'), |
| 148 | 'entity_type' => static::getTableName() |
| 149 | ], |
| 150 | 'multiple' => false, |
| 151 | 'clearFields' => [ |
| 152 | 'entity_type' => static::getTableName(), |
| 153 | 'locale' => $this->get('meta.locale') |
| 154 | ], |
| 155 | 'selfAsArray' => true |
| 156 | ], |
| 157 | ]; |
| 158 | } |
| 159 | |
| 160 | public function preSetupFields() |
| 161 | { |
| 162 | #$this->dataRaw['payment'] = [ |
| 163 | # 'payment_info' => $this->dataRaw['payment'], |
| 164 | # 'paymentcode' => ($this->dataRaw['paymentcode'] ?? null) |
| 165 | #]; |
| 166 | $this->dataRaw['payment_info'] = [ |
| 167 | 'info' => $this->dataRaw['payment'], |
| 168 | 'code' => ($this->dataRaw['paymentcode'] ?? null) |
| 169 | ]; |
| 170 | #unset($this->dataRaw['paymentcode']); |
| 171 | } |
| 172 | |
| 173 | public function preSetup() |
| 174 | { |
| 175 | try { |
| 176 | /* |
| 177 | if (false === $this->get('meta.translated')) { |
| 178 | $this->setStatus(static::STATUS_OLD); |
| 179 | error_log( |
| 180 | 'not translated location - (' . $this->get('id') . ' | ' . |
| 181 | $this->get('meta.locale') . ') - ' . $this->get('name') |
| 182 | ); |
| 183 | return false; |
| 184 | } |
| 185 | else { |
| 186 | error_log( |
| 187 | 'translated location - (' . $this->get('id') . ' | ' . |
| 188 | $this->get('meta.locale') . ') - ' . $this->get('name') |
| 189 | ); |
| 190 | } |
| 191 | */ |
| 192 | $fields = $this->get(['id', 'meta.locale', 'meta.hash']); |
| 193 | $fields[] = static::getTableName(); |
| 194 | $this->setStatus(static::STATUS_OLD); |
| 195 | if ($this->itemNeedsUpdate(...array_values($fields))) { |
| 196 | $this->setStatus(static::STATUS_NEW); |
| 197 | $this->setupFields(); |
| 198 | $this->deleteEntity(); |
| 199 | $this->deleteReferences(); |
| 200 | } |
| 201 | } catch (\Exception $e) { |
| 202 | throw $e; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | public function deleteEntity(): bool |
| 207 | { |
| 208 | try { |
| 209 | return $this->deleteWith( |
| 210 | array_combine(['id', 'locale'], array_values($this->get(['id', 'meta.locale']))) |
| 211 | ); |
| 212 | } catch (\Exception $e) { |
| 213 | throw $e; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | public function clearEntity(array $addWhere = []): bool |
| 218 | { |
| 219 | try { |
| 220 | return $this->deleteWith( |
| 221 | ['locale' => $this->get('meta.locale')] |
| 222 | ); |
| 223 | } catch (\Exception $e) { |
| 224 | throw $e; |
| 225 | } |
| 226 | } |
| 227 | } |