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
210
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 / 4
0.00% covered (danger)
0.00%
0 / 1
30
 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 / 14
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 $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()
20    {
21        $this->referanceMapping = [
22            /*
23            'keywords' => [
24                'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search',
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' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search',
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()
74    {
75        if (array_key_exists('lastupdate', $this->fields) && !empty($this->fields['lastupdate'])) {
76            $this->fields['lastupdate'] = date_format(date_create($this->fields['lastupdate']), 'Y-m-d H:i:s');
77        } elseif (!array_key_exists('lastupdate', $this->fields) || empty($this->fields['lastupdate'])) {
78            $this->fields['lastupdate'] = '1970-01-01 01:00:00';
79        }
80    }
81
82    #[\Override]
83    public function deleteEntity(): bool
84    {
85        try {
86            return $this->deleteWith(
87                array_combine(
88                    ['object_id', 'locale', 'type'],
89                    array_values($this->get(['object_id', 'locale', 'type']))
90                )
91            );
92        } catch (\Exception $e) {
93            throw $e;
94        }
95    }
96
97    #[\Override]
98    public function clearEntity(array $addWhere = []): bool
99    {
100        try {
101            return $this->deleteWith(
102                array_combine(['type', 'locale'], array_values($this->get(['type', 'locale'])))
103            );
104        } catch (\Exception $e) {
105            throw $e;
106        }
107    }
108
109    /**
110     * @SuppressWarnings(PHPMD.UnusedLocalVariable)
111     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
112     */
113    public function itemNeedsUpdateAlt(
114        int $objectId = 0,
115        string $locale = '',
116        string $objectHash = '',
117        string $type = ''
118    ): bool {
119        try {
120            $statment = $this->getPDOAccess()->prepare(
121                "SELECT count(1) AS count FROM meta WHERE object_id = ? AND locale = ? AND hash = ? AND type = ?"
122            );
123            $fields = $this->get(['object_id', 'locale', 'hash', 'type']);
124
125            $result = $statment->execute(array_values($fields));
126
127            $needsUpdate = false;
128            if ($result) {
129                $count = $statment->fetchColumn();
130                if ($count != 1) {
131                    $needsUpdate = true;
132                }
133            }
134            #print_r([$needsUpdate ? 'T' : 'F', $fields]);
135            return $needsUpdate;
136        } catch (\Exception $e) {
137            throw $e;
138        }
139        return false;
140    }
141}