Completed
Push — master ( 094439...4e2e25 )
by Tim
02:38
created

SqlStatements::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Ee\Utils\SqlStatements
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Ee\Utils;
22
23
/**
24
 * Utility class with the SQL statements to use.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import-product-ee
30
 * @link      http://www.techdivision.com
31
 */
32
class SqlStatements extends \TechDivision\Import\Product\Utils\SqlStatements
33
{
34
35
    /**
36
     * The SQL statement to load the actual product with the passed SKU.
37
     *
38
     * @var string
39
     */
40
    const PRODUCT = 'product';
41
42
    /**
43
     * The SQL statement to load the product datetime attribute with the passed row/attribute/store ID.
44
     *
45
     * @var string
46
     */
47
    const PRODUCT_DATETIME = 'product_datetime';
48
49
    /**
50
     * The SQL statement to load the product decimal attribute with the passed row/attribute/store ID.
51
     *
52
     * @var string
53
     */
54
    const PRODUCT_DECIMAL = 'product_decimal';
55
56
    /**
57
     * The SQL statement to load the product integer attribute with the passed row/attribute/store ID.
58
     *
59
     * @var string
60
     */
61
    const PRODUCT_INT = 'product_int';
62
63
    /**
64
     * The SQL statement to load the product text attribute with the passed row/attribute/store ID.
65
     *
66
     * @var string
67
     */
68
    const PRODUCT_TEXT = 'product_text';
69
70
    /**
71
     * The SQL statement to load the product varchar attribute with the passed row/attribute/store ID.
72
     *
73
     * @var string
74
     */
75
    const PRODUCT_VARCHAR = 'product_varchar';
76
77
    /**
78
     * The SQL statement to create a new sequence product value.
79
     *
80
     * @var string
81
     */
82
    const CREATE_SEQUENCE_PRODUCT = 'create.sequence_product';
83
84
    /**
85
     * The SQL statement to create new products.
86
     *
87
     * @var string
88
     */
89
    const CREATE_PRODUCT = 'create.product';
90
91
    /**
92
     * The SQL statement to update an existing product.
93
     *
94
     * @var string
95
     */
96
    const UPDATE_PRODUCT = 'update.product';
97
98
    /**
99
     * The SQL statement to create a new product datetime value.
100
     *
101
     * @var string
102
     */
103
    const CREATE_PRODUCT_DATETIME = 'create.product_datetime';
104
105
    /**
106
     * The SQL statement to update an existing product datetime value.
107
     *
108
     * @var string
109
     */
110
    const UPDATE_PRODUCT_DATETIME = 'update.product_datetime';
111
112
    /**
113
     * The SQL statement to create a new product decimal value.
114
     *
115
     * @var string
116
     */
117
    const CREATE_PRODUCT_DECIMAL = 'create.product_decimal';
118
119
    /**
120
     * The SQL statement to update an existing product decimal value.
121
     *
122
     * @var string
123
     */
124
    const UPDATE_PRODUCT_DECIMAL = 'update.product_decimal';
125
126
    /**
127
     * The SQL statement to create a new product integer value.
128
     *
129
     * @var string
130
     */
131
    const CREATE_PRODUCT_INT = 'create.product_int';
132
133
    /**
134
     * The SQL statement to update an existing product integer value.
135
     *
136
     * @var string
137
     */
138
    const UPDATE_PRODUCT_INT = 'update.product_int';
139
140
    /**
141
     * The SQL statement to create a new product varchar value.
142
     *
143
     * @var string
144
     */
145
    const CREATE_PRODUCT_VARCHAR = 'create.product_varchar';
146
147
    /**
148
     * The SQL statement to update an existing product varchar value.
149
     *
150
     * @var string
151
     */
152
    const UPDATE_PRODUCT_VARCHAR = 'update.product_varchar';
153
154
    /**
155
     * The SQL statement to create a new product text value.
156
     *
157
     * @var string
158
     */
159
    const CREATE_PRODUCT_TEXT = 'create.product_text';
160
161
    /**
162
     * The SQL statement to update an existing product text value.
163
     *
164
     * @var string
165
     */
166
    const UPDATE_PRODUCT_TEXT = 'update.product_text';
167
168
    /**
169
     * The SQL statement to create a product's stock status.
170
     *
171
     * @var string
172
     */
173
    const CREATE_STOCK_ITEM = 'create.stock_item';
174
175
    /**
176
     * The SQL statement to create a product's stock status.
177
     *
178
     * @var string
179
     */
180
    const UPDATE_STOCK_ITEM = 'update.stock_item';
181
182
    /**
183
     * The SQL statements.
184
     *
185
     * @var array
186
     */
187
    private $statements = array(
188
        SqlStatements::PRODUCT =>
189
            'SELECT *
190
               FROM catalog_product_entity
191
              WHERE sku = :sku
192
                AND updated_in > unix_timestamp(now())
193
           ORDER BY created_in ASC',
194
        SqlStatements::PRODUCT_DATETIME =>
195
            'SELECT *
196
               FROM catalog_product_entity_datetime
197
              WHERE row_id = :row_id
198
                AND attribute_id = :attribute_id
199
                AND store_id = :store_id',
200
        SqlStatements::PRODUCT_DECIMAL =>
201
            'SELECT *
202
               FROM catalog_product_entity_decimal
203
              WHERE row_id = :row_id
204
                AND attribute_id = :attribute_id
205
                AND store_id = :store_id',
206
        SqlStatements::PRODUCT_INT =>
207
            'SELECT *
208
               FROM catalog_product_entity_int
209
              WHERE row_id = :row_id
210
                AND attribute_id = :attribute_id
211
                AND store_id = :store_id',
212
        SqlStatements::PRODUCT_TEXT =>
213
            'SELECT *
214
               FROM catalog_product_entity_text
215
              WHERE row_id = :row_id
216
                AND attribute_id = :attribute_id
217
                AND store_id = :store_id',
218
        SqlStatements::PRODUCT_VARCHAR =>
219
            'SELECT *
220
               FROM catalog_product_entity_varchar
221
              WHERE row_id = :row_id
222
                AND attribute_id = :attribute_id
223
                AND store_id = :store_id',
224
        SqlStatements::CREATE_SEQUENCE_PRODUCT =>
225
            'INSERT INTO sequence_product VALUES ()',
226
        SqlStatements::CREATE_PRODUCT =>
227
            'INSERT
228
               INTO catalog_product_entity
229
                    (entity_id,
230
                     created_in,
231
                     updated_in,
232
                     sku,
233
                     created_at,
234
                     updated_at,
235
                     has_options,
236
                     required_options,
237
                     type_id,
238
                     attribute_set_id)
239
             VALUES (:entity_id,
240
                     :created_in,
241
                     :updated_in,
242
                     :sku,
243
                     :created_at,
244
                     :updated_at,
245
                     :has_options,
246
                     :required_options,
247
                     :type_id,
248
                     :attribute_set_id)',
249
        SqlStatements::UPDATE_PRODUCT =>
250
            'UPDATE catalog_product_entity
251
                SET entity_id = :entity_id,
252
                    created_in = :created_in,
253
                    updated_in = :updated_in,
254
                    sku = :sku,
255
                    created_at = :created_at,
256
                    updated_at = :updated_at,
257
                    has_options = :has_options,
258
                    required_options = :required_options,
259
                    type_id = :type_id,
260
                    attribute_set_id = :attribute_set_id
261
              WHERE row_id = :row_id',
262
        SqlStatements::CREATE_PRODUCT_DATETIME =>
263
            'INSERT
264
               INTO catalog_product_entity_datetime
265
                    (row_id,
266
                     attribute_id,
267
                     store_id,
268
                     value)
269
             VALUES (:row_id,
270
                     :attribute_id,
271
                     :store_id,
272
                     :value)',
273
        SqlStatements::UPDATE_PRODUCT_DATETIME =>
274
            'UPDATE catalog_product_entity_datetime
275
                SET row_id = :row_id,
276
                    attribute_id = :attribute_id,
277
                    store_id = :store_id,
278
                    value = :value
279
              WHERE value_id = :value_id',
280
        SqlStatements::CREATE_PRODUCT_DECIMAL =>
281
            'INSERT
282
               INTO catalog_product_entity_decimal
283
                    (row_id,
284
                     attribute_id,
285
                     store_id,
286
                     value)
287
             VALUES (:row_id,
288
                     :attribute_id,
289
                     :store_id,
290
                     :value)',
291
        SqlStatements::UPDATE_PRODUCT_DECIMAL =>
292
            'UPDATE catalog_product_entity_decimal
293
                SET row_id = :row_id,
294
                    attribute_id = :attribute_id,
295
                    store_id = :store_id,
296
                    value = :value
297
              WHERE value_id = :value_id',
298
        SqlStatements::CREATE_PRODUCT_INT =>
299
            'INSERT
300
               INTO catalog_product_entity_int
301
                    (row_id,
302
                     attribute_id,
303
                     store_id,
304
                     value)
305
             VALUES (:row_id,
306
                     :attribute_id,
307
                     :store_id,
308
                     :value)',
309
        SqlStatements::UPDATE_PRODUCT_INT =>
310
            'UPDATE catalog_product_entity_int
311
                SET row_id = :row_id,
312
                    attribute_id = :attribute_id,
313
                    store_id = :store_id,
314
                    value = :value
315
              WHERE value_id = :value_id',
316
        SqlStatements::CREATE_PRODUCT_VARCHAR =>
317
            'INSERT
318
               INTO catalog_product_entity_varchar
319
                    (row_id,
320
                     attribute_id,
321
                     store_id,
322
                     value)
323
             VALUES (:row_id,
324
                     :attribute_id,
325
                     :store_id,
326
                     :value)',
327
        SqlStatements::UPDATE_PRODUCT_VARCHAR =>
328
            'UPDATE catalog_product_entity_varchar
329
                SET row_id = :row_id,
330
                    attribute_id = :attribute_id,
331
                    store_id = :store_id,
332
                    value = :value
333
              WHERE value_id = :value_id',
334
        SqlStatements::CREATE_PRODUCT_TEXT =>
335
            'INSERT
336
               INTO catalog_product_entity_text
337
                    (row_id,
338
                     attribute_id,
339
                     store_id,
340
                     value)
341
             VALUES (:row_id,
342
                     :attribute_id,
343
                     :store_id,
344
                     :value)',
345
        SqlStatements::UPDATE_PRODUCT_TEXT =>
346
            'UPDATE catalog_product_entity_text
347
                SET row_id = :row_id,
348
                    attribute_id = :attribute_id,
349
                    store_id = :store_id,
350
                    value = :value
351
              WHERE value_id = :value_id',
352
        SqlStatements::CREATE_STOCK_ITEM =>
353
            'INSERT
354
               INTO cataloginventory_stock_item
355
                    (product_id,
356
                     stock_id,
357
                     website_id,
358
                     qty,
359
                     min_qty,
360
                     use_config_min_qty,
361
                     is_qty_decimal,
362
                     backorders,
363
                     use_config_backorders,
364
                     min_sale_qty,
365
                     use_config_min_sale_qty,
366
                     max_sale_qty,
367
                     use_config_max_sale_qty,
368
                     is_in_stock,
369
                     notify_stock_qty,
370
                     use_config_notify_stock_qty,
371
                     manage_stock,
372
                     use_config_manage_stock,
373
                     use_config_qty_increments,
374
                     qty_increments,
375
                     use_config_enable_qty_inc,
376
                     enable_qty_increments,
377
                     is_decimal_divided,
378
                     deferred_stock_update,
379
                     use_config_deferred_stock_update)
380
             VALUES (:product_id,
381
                     :stock_id,
382
                     :website_id,
383
                     :qty,
384
                     :min_qty,
385
                     :use_config_min_qty,
386
                     :is_qty_decimal,
387
                     :backorders,
388
                     :use_config_backorders,
389
                     :min_sale_qty,
390
                     :use_config_min_sale_qty,
391
                     :max_sale_qty,
392
                     :use_config_max_sale_qty,
393
                     :is_in_stock,
394
                     :notify_stock_qty,
395
                     :use_config_notify_stock_qty,
396
                     :manage_stock,
397
                     :use_config_manage_stock,
398
                     :use_config_qty_increments,
399
                     :qty_increments,
400
                     :use_config_enable_qty_inc,
401
                     :enable_qty_increments,
402
                     :is_decimal_divided,
403
                     :deferred_stock_update,
404
                     :use_config_deferred_stock_update)',
405
        SqlStatements::UPDATE_STOCK_ITEM =>
406
            'UPDATE cataloginventory_stock_item
407
                SET product_id = :product_id,
408
                    stock_id = :stock_id,
409
                    website_id = :website_id,
410
                    qty = :qty,
411
                    min_qty = :min_qty,
412
                    use_config_min_qty = :use_config_min_qty,
413
                    is_qty_decimal = :is_qty_decimal,
414
                    backorders = :backorders,
415
                    use_config_backorders = :use_config_backorders,
416
                    min_sale_qty = :min_sale_qty,
417
                    use_config_min_sale_qty = :use_config_min_sale_qty,
418
                    max_sale_qty = :max_sale_qty,
419
                    use_config_max_sale_qty = :use_config_max_sale_qty,
420
                    is_in_stock = :is_in_stock,
421
                    low_stock_date = :low_stock_date,
422
                    notify_stock_qty = :notify_stock_qty,
423
                    use_config_notify_stock_qty = :use_config_notify_stock_qty,
424
                    manage_stock = :manage_stock,
425
                    use_config_manage_stock = :use_config_manage_stock,
426
                    stock_status_changed_auto = :stock_status_changed_auto,
427
                    use_config_qty_increments = :use_config_qty_increments,
428
                    qty_increments = :qty_increments,
429
                    use_config_enable_qty_inc = :use_config_enable_qty_inc,
430
                    enable_qty_increments = :enable_qty_increments,
431
                    is_decimal_divided = :is_decimal_divided,
432
                    deferred_stock_update = :deferred_stock_update,
433
                    use_config_deferred_stock_update = :use_config_deferred_stock_update
434
              WHERE item_id = :item_id'
435
    );
436
437
    /**
438
     * Initialize the the SQL statements.
439
     */
440
    public function __construct()
441
    {
442
443
        // call the parent constructor
444
        parent::__construct();
0 ignored issues
show
Bug introduced by
The method __construct() cannot be called from this context as it is declared private in class TechDivision\Import\Utils\SqlStatements.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
Unused Code introduced by
The call to the method TechDivision\Import\Prod...atements::__construct() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
445
446
        // merge the class statements
447
        foreach ($this->statements as $key => $statement) {
448
            $this->preparedStatements[$key] = $statement;
0 ignored issues
show
Bug introduced by
The property preparedStatements does not seem to exist. Did you mean statements?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
449
        }
450
    }
451
}
452