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    protected function setupMapping()
19    {
20        $this->referanceMapping = [
21            /*
22            'keywords' => [
23                'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search',
24                'neededFields' => [
25                    'object_id' => 'object_id',
26                    'locale' => 'locale',
27                    'keywords' => 'search_value',
28                    'type' => 'entity_type',
29                ],
30                'addFields' => [
31                    'search_type' => 'keywords'
32                ],
33                'deleteFields' => [
34                    'object_id' => $this->get('id'),
35                    'locale' => $this->get('locale'),
36                    'entity_type' => $this->get('type')
37                ],
38                'multiple' => false,
39                'clearFields' => [
40                    'entity_type' => $this->get('type'),
41                    'locale' => $this->get('locale')
42                ],
43                'selfAsArray' => true
44            ],
45            'titles' => [
46                'class' => 'BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Search',
47                'neededFields' => [
48                    'object_id' => 'object_id',
49                    'locale' => 'locale',
50                    'titles' => 'search_value',
51                    'type' => 'entity_type',
52                ],
53                'addFields' => [
54                    'search_type' => 'titles'
55                ],
56                'deleteFields' => [
57                    'object_id' => $this->get('id'),
58                    'locale' => $this->get('locale'),
59                    'entity_type' => $this->get('type')
60                ],
61                'multiple' => false,
62                'clearFields' => [
63                    'entity_type' => $this->get('type'),
64                    'locale' => $this->get('locale')
65                ],
66                'selfAsArray' => true
67            ]*/
68        ];
69    }
70
71    public function postSetupFields()
72    {
73        if (array_key_exists('lastupdate', $this->fields) && !empty($this->fields['lastupdate'])) {
74            $this->fields['lastupdate'] = date_format(date_create($this->fields['lastupdate']), 'Y-m-d H:i:s');
75        } elseif (!array_key_exists('lastupdate', $this->fields) || empty($this->fields['lastupdate'])) {
76            $this->fields['lastupdate'] = '1970-01-01 01:00:00';
77        }
78    }
79
80    public function deleteEntity(): bool
81    {
82        try {
83            return $this->deleteWith(
84                array_combine(
85                    ['object_id', 'locale', 'type'],
86                    array_values($this->get(['object_id', 'locale', 'type']))
87                )
88            );
89        } catch (\Exception $e) {
90            throw $e;
91        }
92    }
93
94    public function clearEntity(array $addWhere = []): bool
95    {
96        try {
97            return $this->deleteWith(
98                array_combine(['type', 'locale'], array_values($this->get(['type', 'locale'])))
99            );
100        } catch (\Exception $e) {
101            throw $e;
102        }
103    }
104
105    /**
106     * @SuppressWarnings(PHPMD.UnusedLocalVariable)
107     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
108     */
109    public function itemNeedsUpdateAlt(
110        int $objectId = 0,
111        string $locale = '',
112        string $objectHash = '',
113        string $type = ''
114    ): bool {
115        try {
116            $statment = $this->getPDOAccess()->prepare(
117                "SELECT count(1) AS count FROM meta WHERE object_id = ? AND locale = ? AND hash = ? AND type = ?"
118            );
119            $fields = $this->get(['object_id', 'locale', 'hash', 'type']);
120
121            $result = $statment->execute(array_values($fields));
122
123            $needsUpdate = false;
124            if ($result) {
125                $count = $statment->fetchColumn();
126                if ($count != 1) {
127                    $needsUpdate = true;
128                }
129            }
130            #print_r([$needsUpdate ? 'T' : 'F', $fields]);
131            return $needsUpdate;
132        } catch (\Exception $e) {
133            throw $e;
134        }
135        return false;
136    }
137}