SqlStatementRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Repositories\SqlStatements
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2018 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-customer-address
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Address\Repositories;
16
17
use TechDivision\Import\Customer\Address\Utils\SqlStatementKeys;
18
19
/**
20
 * Repository class with the SQL statements to use.
21
 *
22
 * @author    Tim Wagner <[email protected]>
23
 * @copyright 2018 TechDivision GmbH <[email protected]>
24
 * @license   https://opensource.org/licenses/MIT
25
 * @link      https://github.com/techdivision/import-customer-address
26
 * @link      http://www.techdivision.com
27
 */
28
class SqlStatementRepository extends \TechDivision\Import\Repositories\SqlStatementRepository
29
{
30
31
    /**
32
     * The SQL statements.
33
     *
34
     * @var array
35
     */
36
    private $statements = array(
37
        SqlStatementKeys::CUSTOMER_ADDRESS =>
38
            'SELECT *
39
               FROM ${table:customer_address_entity}
40
              WHERE entity_id = :entity_id',
41
        SqlStatementKeys::CUSTOMER_ADDRESS_INCREMENT_ID =>
42
            'SELECT *
43
               FROM ${table:customer_address_entity}
44
              WHERE increment_id = :increment_id
45
                AND parent_id = :parent_id',
46
        SqlStatementKeys::CUSTOMER_ADDRESSES =>
47
            'SELECT *
48
               FROM ${table:customer_address_entity}',
49
        SqlStatementKeys::CUSTOMER_ADDRESS_DATETIMES =>
50
            'SELECT *
51
               FROM ${table:customer_address_entity_datetime}
52
              WHERE entity_id = :entity_id',
53
        SqlStatementKeys::CUSTOMER_ADDRESS_DECIMALS =>
54
            'SELECT *
55
               FROM ${table:customer_address_entity_decimal}
56
              WHERE entity_id = :entity_id',
57
        SqlStatementKeys::CUSTOMER_ADDRESS_INTS =>
58
            'SELECT *
59
               FROM ${table:customer_address_entity_int}
60
              WHERE entity_id = :entity_id',
61
        SqlStatementKeys::CUSTOMER_ADDRESS_TEXTS =>
62
            'SELECT *
63
               FROM ${table:customer_address_entity_text}
64
              WHERE entity_id = :entity_id',
65
        SqlStatementKeys::CUSTOMER_ADDRESS_VARCHARS =>
66
            'SELECT *
67
               FROM ${table:customer_address_entity_varchar}
68
              WHERE entity_id = :entity_id',
69
        SqlStatementKeys::CUSTOMER_ADDRESS_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_VALUE =>
70
            'SELECT t1.*
71
               FROM ${table:customer_address_entity_varchar} t1,
72
                    ${table:eav_attribute} t2
73
              WHERE t2.attribute_code = :attribute_code
74
                AND t2.entity_type_id = :entity_type_id
75
                AND t1.attribute_id = t2.attribute_id
76
                AND t1.value = :value',
77
        SqlStatementKeys::CREATE_CUSTOMER_ADDRESS =>
78
            'INSERT
79
               INTO ${table:customer_address_entity}
80
                    (increment_id,
81
                     parent_id,
82
                     created_at,
83
                     updated_at,
84
                     is_active,
85
                     city,
86
                     company,
87
                     country_id,
88
                     fax,
89
                     firstname,
90
                     lastname,
91
                     middlename,
92
                     postcode,
93
                     prefix,
94
                     region,
95
                     region_id,
96
                     street,
97
                     suffix,
98
                     telephone,
99
                     vat_id,
100
                     vat_is_valid,
101
                     vat_request_date,
102
                     vat_request_id,
103
                     vat_request_success)
104
             VALUES (:increment_id,
105
                     :parent_id,
106
                     :created_at,
107
                     :updated_at,
108
                     :is_active,
109
                     :city,
110
                     :company,
111
                     :country_id,
112
                     :fax,
113
                     :firstname,
114
                     :lastname,
115
                     :middlename,
116
                     :postcode,
117
                     :prefix,
118
                     :region,
119
                     :region_id,
120
                     :street,
121
                     :suffix,
122
                     :telephone,
123
                     :vat_id,
124
                     :vat_is_valid,
125
                     :vat_request_date,
126
                     :vat_request_id,
127
                     :vat_request_success)',
128
        SqlStatementKeys::UPDATE_CUSTOMER_ADDRESS =>
129
             'UPDATE ${table:customer_address_entity}
130
                 SET increment_id = :increment_id,
131
                     parent_id = :parent_id,
132
                     created_at = :created_at,
133
                     updated_at = :updated_at,
134
                     is_active = :is_active,
135
                     city = :city,
136
                     company = :company,
137
                     country_id = :country_id,
138
                     fax = :fax,
139
                     firstname = :firstname,
140
                     lastname = :lastname,
141
                     middlename = :middlename,
142
                     postcode = :postcode,
143
                     prefix = :prefix,
144
                     region = :region,
145
                     region_id = :region_id,
146
                     street = :street,
147
                     suffix = :suffix,
148
                     telephone = :telephone,
149
                     vat_id = :vat_id,
150
                     vat_is_valid = :vat_is_valid,
151
                     vat_request_date = :vat_request_date,
152
                     vat_request_id = :vat_request_id,
153
                     vat_request_success = :vat_request_success
154
               WHERE entity_id = :entity_id',
155
        SqlStatementKeys::DELETE_CUSTOMER_ADDRESS =>
156
             'DELETE
157
                FROM ${table:customer_address_entity}
158
               WHERE entity_id = :entity_id',
159
        SqlStatementKeys::CREATE_CUSTOMER_ADDRESS_DATETIME =>
160
            'INSERT
161
               INTO ${table:customer_address_entity_datetime}
162
                    (entity_id,
163
                     attribute_id,
164
                     value)
165
            VALUES (:entity_id,
166
                    :attribute_id,
167
                    :value)',
168
        SqlStatementKeys::UPDATE_CUSTOMER_ADDRESS_DATETIME =>
169
            'UPDATE ${table:customer_address_entity_datetime}
170
                SET entity_id = :entity_id,
171
                    attribute_id = :attribute_id,
172
                    value = :value
173
              WHERE value_id = :value_id',
174
        SqlStatementKeys::DELETE_CUSTOMER_ADDRESS_DATETIME =>
175
            'DELETE
176
               FROM ${table:customer_address_entity_datetime}
177
              WHERE value_id = :value_id',
178
        SqlStatementKeys::CREATE_CUSTOMER_ADDRESS_DECIMAL =>
179
            'INSERT
180
               INTO ${table:customer_address_entity_decimal}
181
                    (entity_id,
182
                     attribute_id,
183
                     value)
184
            VALUES (:entity_id,
185
                    :attribute_id,
186
                    :value)',
187
        SqlStatementKeys::UPDATE_CUSTOMER_ADDRESS_DECIMAL =>
188
            'UPDATE ${table:customer_address_entity_decimal}
189
                SET entity_id = :entity_id,
190
                    attribute_id = :attribute_id,
191
                    value = :value
192
              WHERE value_id = :value_id',
193
        SqlStatementKeys::DELETE_CUSTOMER_ADDRESS_DECIMAL =>
194
            'DELETE
195
               FROM ${table:customer_address_entity_decimal}
196
              WHERE value_id = :value_id',
197
        SqlStatementKeys::CREATE_CUSTOMER_ADDRESS_INT =>
198
            'INSERT
199
               INTO ${table:customer_address_entity_int}
200
                    (entity_id,
201
                     attribute_id,
202
                     value)
203
             VALUES (:entity_id,
204
                     :attribute_id,
205
                     :value)',
206
        SqlStatementKeys::UPDATE_CUSTOMER_ADDRESS_INT =>
207
            'UPDATE ${table:customer_address_entity_int}
208
                SET entity_id = :entity_id,
209
                    attribute_id = :attribute_id,
210
                    value = :value
211
              WHERE value_id = :value_id',
212
        SqlStatementKeys::DELETE_CUSTOMER_ADDRESS_INT =>
213
            'DELETE
214
               FROM ${table:customer_address_entity_int}
215
              WHERE value_id = :value_id',
216
        SqlStatementKeys::CREATE_CUSTOMER_ADDRESS_VARCHAR =>
217
            'INSERT
218
               INTO ${table:customer_address_entity_varchar}
219
                    (entity_id,
220
                     attribute_id,
221
                     value)
222
             VALUES (:entity_id,
223
                     :attribute_id,
224
                     :value)',
225
        SqlStatementKeys::UPDATE_CUSTOMER_ADDRESS_VARCHAR =>
226
            'UPDATE ${table:customer_address_entity_varchar}
227
                SET entity_id = :entity_id,
228
                    attribute_id = :attribute_id,
229
                    value = :value
230
              WHERE value_id = :value_id',
231
        SqlStatementKeys::DELETE_CUSTOMER_ADDRESS_VARCHAR =>
232
            'DELETE
233
               FROM ${table:customer_address_entity_varchar}
234
              WHERE value_id = :value_id',
235
        SqlStatementKeys::CREATE_CUSTOMER_ADDRESS_TEXT =>
236
            'INSERT
237
               INTO ${table:customer_address_entity_text}
238
                    (entity_id,
239
                     attribute_id,
240
                     value)
241
             VALUES (:entity_id,
242
                     :attribute_id,
243
                     :value)',
244
        SqlStatementKeys::UPDATE_CUSTOMER_ADDRESS_TEXT =>
245
            'UPDATE ${table:customer_address_entity_text}
246
                SET entity_id = :entity_id,
247
                    attribute_id = :attribute_id,
248
                    value = :value
249
              WHERE value_id = :value_id',
250
        SqlStatementKeys::DELETE_CUSTOMER_ADDRESS_TEXT =>
251
            'DELETE
252
               FROM ${table:customer_address_entity_text}
253
              WHERE value_id = :value_id',
254
    );
255
256
    /**
257
     * Initializes the SQL statement repository with the primary key and table prefix utility.
258
     *
259
     * @param \IteratorAggregate<\TechDivision\Import\Dbal\Utils\SqlCompilerInterface> $compilers The array with the compiler instances
260
     */
261
    public function __construct(\IteratorAggregate $compilers)
262
    {
263
264
        // pass primary key + table prefix utility to parent instance
265
        parent::__construct($compilers);
266
267
        // compile the SQL statements
268
        $this->compile($this->statements);
269
    }
270
}
271