Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Authority
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 5
90
0.00% covered (danger)
0.00%
0 / 1
 setupMapping
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
2
 preSetupFields
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 preSetup
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
 deleteEntity
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 clearEntity
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BO\Zmsdldb\Importer\MySQL\Entity;
4
5class Authority extends Base
6{
7    protected array $fieldMapping = [
8        'id' => 'id',
9        'name' => 'name',
10        'parent_id' => 'parent_id',
11        'meta.locale' => 'locale',
12        'locations' => 'locations_json',
13        'relation' => 'relation_json',
14        'contact' => 'contact_json',
15        '__RAW__' => 'data_json'
16    ];
17
18    #[\Override]
19    protected function setupMapping(): void
20    {
21        $this->referanceMapping = [
22            'meta' => [
23                'class' => Meta::class,
24                'neededFields' => [
25                    'id' => 'object_id',
26                    'meta.locale' => 'locale'
27                ],
28                'addFields' => [
29                    'type' => static::getTableName()
30                ],
31                'deleteFields' => [
32                    'object_id' => $this->get('id'),
33                    'locale' => $this->get('meta.locale'),
34                    'type' => static::getTableName()
35                ],
36                'clearFields' => ['type' => static::getTableName(), 'locale' => $this->get('meta.locale')],
37                'multiple' => false
38            ],
39            'locations' => [
40                'class' => AuthorityLocation::class,
41                'neededFields' => ['id' => 'authority_id', 'meta.locale' => 'locale'],
42                'addFields' => [
43
44                ],
45                'deleteFields' => [
46                    'authority_id' => $this->get('id'),
47                    'locale' => $this->get('meta.locale')
48                ],
49                'clearFields' => [
50                    'locale' => $this->get('meta.locale')
51                ]
52            ],
53        ];
54    }
55
56    #[\Override]
57    public function preSetupFields(): void
58    {
59        $this->dataRaw['parent_id'] = ($this->dataRaw['parent_id'] ?? 0);
60    }
61
62    #[\Override]
63    public function preSetup(): void
64    {
65        try {
66            $this->setStatus(static::STATUS_OLD);
67            if ($this->entityNeedsUpdate()) {
68                $this->setStatus(static::STATUS_NEW);
69                $this->setupFields();
70                $this->deleteEntity();
71                $this->deleteReferences();
72            }
73        } catch (\Exception $e) {
74            throw $e;
75        }
76    }
77
78    #[\Override]
79    public function deleteEntity(): void
80    {
81        try {
82            $this->deleteWith(
83                array_combine(['id', 'locale'], array_values($this->get(['id', 'meta.locale'])))
84            );
85        } catch (\Exception $e) {
86            throw $e;
87        }
88    }
89
90    #[\Override]
91    public function clearEntity(array $addWhere = []): void
92    {
93        try {
94            $this->deleteWith(
95                ['locale' => $this->get('meta.locale')]
96            );
97        } catch (\Exception $e) {
98            throw $e;
99        }
100    }
101}