Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 80
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Meta
0.00% covered (danger)
0.00%
0 / 80
0.00% covered (danger)
0.00%
0 / 5
182
0.00% covered (danger)
0.00%
0 / 1
 setupMapping
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 1
2
 postSetupFields
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
 deleteEntity
0.00% covered (danger)
0.00%
0 / 8
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
 itemNeedsUpdateAlt
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace BO\Zmsdldb\Importer\MySQL\Entity;
4
5class Meta extends Base
6{
7    protected array $fieldMapping = [
8        'object_id' => 'object_id',
9        'hash' => 'hash',
10        'locale' => 'locale',
11        'lastupdate' => 'lastupdate',
12        'keywords' => 'keywords',
13        'url' => 'url',
14        'type' => 'type',
15        'titles' => 'titles_json'
16    ];
17
18    #[\Override]
19    protected function setupMapping(): void
20    {
21        $this->referanceMapping = [
22            /*
23            'keywords' => [
24                'class' => Search::class,
25                'neededFields' => [
26                    'object_id' => 'object_id',
27                    'locale' => 'locale',
28                    'keywords' => 'search_value',
29                    'type' => 'entity_type',
30                ],
31                'addFields' => [
32                    'search_type' => 'keywords'
33                ],
34                'deleteFields' => [
35                    'object_id' => $this->get('id'),
36                    'locale' => $this->get('locale'),
37                    'entity_type' => $this->get('type')
38                ],
39                'multiple' => false,
40                'clearFields' => [
41                    'entity_type' => $this->get('type'),
42                    'locale' => $this->get('locale')
43                ],
44                'selfAsArray' => true
45            ],
46            'titles' => [
47                'class' => Search::class,
48                'neededFields' => [
49                    'object_id' => 'object_id',
50                    'locale' => 'locale',
51                    'titles' => 'search_value',
52                    'type' => 'entity_type',
53                ],
54                'addFields' => [
55                    'search_type' => 'titles'
56                ],
57                'deleteFields' => [
58                    'object_id' => $this->get('id'),
59                    'locale' => $this->get('locale'),
60                    'entity_type' => $this->get('type')
61                ],
62                'multiple' => false,
63                'clearFields' => [
64                    'entity_type' => $this->get('type'),
65                    'locale' => $this->get('locale')
66                ],
67                'selfAsArray' => true
68            ]*/
69        ];
70    }
71
72    #[\Override]
73    public function postSetupFields(): void
74    {
75        $lastupdate = $this->fields['lastupdate'] ?? null;
76        $created = is_string($lastupdate) && $lastupdate !== '' ? date_create($lastupdate) : false;
77        if ($created instanceof \DateTimeInterface) {
78            $this->fields['lastupdate'] = $created->format('Y-m-d H:i:s');
79        } else {
80            $this->fields['lastupdate'] = '1970-01-01 01:00:00';
81        }
82    }
83
84    #[\Override]
85    public function deleteEntity(): void
86    {
87        try {
88            $this->deleteWith(
89                array_combine(
90                    ['object_id', 'locale', 'type'],
91                    array_values($this->get(['object_id', 'locale', 'type']))
92                )
93            );
94        } catch (\Exception $e) {
95            throw $e;
96        }
97    }
98
99    #[\Override]
100    public function clearEntity(array $addWhere = []): void
101    {
102        try {
103            $this->deleteWith(
104                array_combine(['type', 'locale'], array_values($this->get(['type', 'locale'])))
105            );
106        } catch (\Exception $e) {
107            throw $e;
108        }
109    }
110
111    public function itemNeedsUpdateAlt(): bool
112    {
113        try {
114            $statment = $this->getPDOAccess()->prepare(
115                "SELECT count(1) AS count FROM meta WHERE object_id = ? AND locale = ? AND hash = ? AND type = ?"
116            );
117            $fields = $this->get(['object_id', 'locale', 'hash', 'type']);
118
119            $result = $statment->execute(array_values($fields));
120
121            $needsUpdate = false;
122            if ($result) {
123                $count = $statment->fetchColumn();
124                if ($count != 1) {
125                    $needsUpdate = true;
126                }
127            }
128            return $needsUpdate;
129        } catch (\Exception $e) {
130            throw $e;
131        }
132    }
133}