Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Settings | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| runImport | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdldb\Importer\MySQL; |
| 4 | |
| 5 | class Settings extends Base |
| 6 | { |
| 7 | protected bool $getCurrentEntitys = false; |
| 8 | /** @var class-string<\BO\Zmsdldb\Importer\MySQL\Entity\Base>|null */ |
| 9 | protected ?string $entityClass = \BO\Zmsdldb\Importer\MySQL\Entity\Setting::class; |
| 10 | |
| 11 | /** @psalm-api */ |
| 12 | #[\Override] |
| 13 | public function runImport(): bool |
| 14 | { |
| 15 | try { |
| 16 | $shifted = array_shift($this->importData); |
| 17 | if (!is_array($shifted)) { |
| 18 | throw new \RuntimeException('Invalid settings import data'); |
| 19 | } |
| 20 | $this->importData = $shifted; |
| 21 | |
| 22 | $settings = $this->importData['settings'] ?? []; |
| 23 | if (!is_array($settings)) { |
| 24 | throw new \RuntimeException('Invalid settings payload'); |
| 25 | } |
| 26 | $settings['boroughs'] = json_encode(($this->importData['boroughs'] ?? '')); |
| 27 | $settings['office'] = json_encode(($this->importData['office'] ?? '')); |
| 28 | |
| 29 | foreach ($settings as $name => $value) { |
| 30 | $setting = $this->createEntity(['name' => $name, 'value' => $value]); |
| 31 | $setting->save(); |
| 32 | } |
| 33 | } catch (\Exception $e) { |
| 34 | throw $e; |
| 35 | } |
| 36 | |
| 37 | return true; |
| 38 | } |
| 39 | } |