Completed
Pull Request — master (#12)
by Tim
02:54
created

SqlStatements   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 537
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 537
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\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-attribute
30
 * @link      http://www.techdivision.com
31
 */
32
class SqlStatements extends \TechDivision\Import\Utils\SqlStatements
33
{
34
35
    /**
36
     * The SQL statement to load the EAV attribute with the passed attribute ID.
37
     *
38
     * @var string
39
     */
40
    const ATTRIBUTE = 'attribute';
41
42
    /**
43
     * The SQL statement to load the EAV catalog attribute with the passed attribute ID.
44
     *
45
     * @var string
46
     */
47
    const CATALOG_ATTRIBUTE = 'catalog_attribute';
48
49
    /**
50
     * The SQL statement to load the EAV attribute by its attribute code.
51
     *
52
     * @var string
53
     */
54
    const ATTRIBUTE_BY_ATTRIBUTE_CODE = 'attribute.by.attribute_code';
55
56
    /**
57
     * The SQL statement to load the EAV attribute label by its attribute code and store ID.
58
     *
59
     * @var string
60
     */
61
    const ATTRIBUTE_LABEL_BY_ATTRIBUTE_CODE_AND_STORE_ID = 'attribute_label.by.attribute_code.and.store_id';
62
63
    /**
64
     * The SQL statement to load the EAV attribute option by its attribute code, store ID and value.
65
     *
66
     * @var string
67
     */
68
    const ATTRIBUTE_OPTION_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE = 'attribute_option.by.attribute_code.and.store_id.and.value';
69
70
    /**
71
     * The SQL statement to load the EAV attribute option swtach by its attribute code, store ID, value and type.
72
     *
73
     * @var string
74
     */
75
    const ATTRIBUTE_OPTION_SWATCH_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE_AND_TYPE = 'attribute_option_swatch.by.attribute_code.and.store_id.and.value.and.type';
76
77
    /**
78
     * The SQL statement to load the EAV catalog attribute by its attribute code and entity type ID.
79
     *
80
     * @var string
81
     */
82
    const CATALOG_ATTRIBUTE_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID = 'catalog_attribute.by.attribute_code.and.entity_type_id';
83
84
    /**
85
     * The SQL statement to load the EAV entity attribute by its attribute ID, attribute set ID and attribute group ID.
86
     *
87
     * @var string
88
     */
89
    const ENTITY_ATTRIBUTE_BY_ATTRIBUTE_ID_AND_ATTRIBUTE_SET_ID_AND_ATTRIBUTE_GROUP_ID = 'entity_attribute.by.attribute_id.and.attribute_set_id.and.attribute_group_id';
90
91
    /**
92
     * The SQL statement to create a new EAV attribute.
93
     *
94
     * @var string
95
     */
96
    const CREATE_ATTRIBUTE = 'create.attribute';
97
98
    /**
99
     * The SQL statement to create a new EAV entity attribute.
100
     *
101
     * @var string
102
     */
103
    const CREATE_ENTITY_ATTRIBUTE = 'create.entity_attribute';
104
105
    /**
106
     * The SQL statement to create a new EAV attribute label.
107
     *
108
     * @var string
109
     */
110
    const CREATE_ATTRIBUTE_LABEL = 'create.attribute_label';
111
112
    /**
113
     * The SQL statement to create a new EAV attribute option.
114
     *
115
     * @var string
116
     */
117
    const CREATE_ATTRIBUTE_OPTION = 'create.attribute_option';
118
119
    /**
120
     * The SQL statement to create a new EAV attribute option value.
121
     *
122
     * @var string
123
     */
124
    const CREATE_ATTRIBUTE_OPTION_VALUE = 'create.attribute_option_value';
125
126
    /**
127
     * The SQL statement to create a new EAV attribute option swatch value.
128
     *
129
     * @var string
130
     */
131
    const CREATE_ATTRIBUTE_OPTION_SWATCH = 'create.attribute_option_swatch';
132
133
    /**
134
     * The SQL statement to create a new EAV catalog attribute.
135
     *
136
     * @var string
137
     */
138
    const CREATE_CATALOG_ATTRIBUTE = 'create.catalog_attribute';
139
140
    /**
141
     * The SQL statement to update an existing EAV attribute.
142
     *
143
     * @var string
144
     */
145
    const UPDATE_ATTRIBUTE = 'update.attribute';
146
147
    /**
148
     * The SQL statement to update an existing EAV catalog attribute.
149
     *
150
     * @var string
151
     */
152
    const UPDATE_CATALOG_ATTRIBUTE = 'update.catalog_attribute';
153
154
    /**
155
     * The SQL statement to update an existing EAV attribute label.
156
     *
157
     * @var string
158
     */
159
    const UPDATE_ENTITY_ATTRIBUTE = 'update.entity_attribute';
160
161
    /**
162
     * The SQL statement to update an existing EAV attribute label.
163
     *
164
     * @var string
165
     */
166
    const UPDATE_ATTRIBUTE_LABEL = 'update.attribute_label';
167
168
    /**
169
     * The SQL statement to update an existing EAV attribute option.
170
     *
171
     * @var string
172
     */
173
    const UPDATE_ATTRIBUTE_OPTION = 'update.attribute_option';
174
175
    /**
176
     * The SQL statement to update an existing EAV attribute option value.
177
     *
178
     * @var string
179
     */
180
    const UPDATE_ATTRIBUTE_OPTION_VALUE = 'update.attribute_option_value';
181
182
    /**
183
     * The SQL statement to update an existing EAV attribute option value.
184
     *
185
     * @var string
186
     */
187
    const UPDATE_ATTRIBUTE_OPTION_SWATCH = 'update.attribute_option_swatch';
188
189
    /**
190
     * The SQL statement to remove a existing EAV attribute.
191
     *
192
     * @var string
193
     */
194
    const DELETE_ATTRIBUTE = 'delete.attribute';
195
196
    /**
197
     * The SQL statement to remove a existing EAV entity attribute.
198
     *
199
     * @var string
200
     */
201
    const DELETE_ENTITY_ATTRIBUTE = 'delete.entity_attribute';
202
203
    /**
204
     * The SQL statement to remove a existing EAV attribute label.
205
     *
206
     * @var string
207
     */
208
    const DELETE_ATTRIBUTE_LABEL = 'delete.attribute_label';
209
210
    /**
211
     * The SQL statement to remove a existing EAV attribute option.
212
     *
213
     * @var string
214
     */
215
    const DELETE_ATTRIBUTE_OPTION = 'delete.attribute_option';
216
217
    /**
218
     * The SQL statement to remove a existing EAV attribute option value.
219
     *
220
     * @var string
221
     */
222
    const DELETE_ATTRIBUTE_OPTION_VALUE = 'delete.attribute_option_value';
223
224
    /**
225
     * The SQL statement to remove a existing EAV attribute option swatch value.
226
     *
227
     * @var string
228
     */
229
    const DELETE_ATTRIBUTE_OPTION_SWATCH = 'delete.attribute_option_swatch';
230
231
    /**
232
     * The SQL statement to remove a existing EAV catalog attribute.
233
     *
234
     * @var string
235
     */
236
    const DELETE_CATALOG_ATTRIBUTE = 'delete.catalog_attribute';
237
238
    /**
239
     * The SQL statement to remove a existing EAV attribute by its attribute code.
240
     *
241
     * @var string
242
     */
243
    const DELETE_ATTRIBUTE_BY_ATTRIBUTE_CODE = 'delete.attribute.by.attribute_code';
244
245
    /**
246
     * The SQL statements.
247
     *
248
     * @var array
249
     */
250
    private $statements = array(
251
        SqlStatements::ATTRIBUTE =>
252
            'SELECT * FROM eav_attribute WHERE attribute_id = :attribute_id',
253
        SqlStatements::CATALOG_ATTRIBUTE =>
254
            'SELECT attribute_id,
255
                    frontend_input_renderer,
256
                    is_global,
257
                    is_visible,
258
                    is_searchable,
259
                    is_filterable,
260
                    is_comparable,
261
                    is_visible_on_front,
262
                    is_html_allowed_on_front,
263
                    is_used_for_price_rules,
264
                    is_filterable_in_search,
265
                    used_in_product_listing,
266
                    used_for_sort_by,
267
                    apply_to,
268
                    is_visible_in_advanced_search,
269
                    position,
270
                    is_wysiwyg_enabled,
271
                    is_used_for_promo_rules,
272
                    is_required_in_admin_store,
273
                    is_used_in_grid,
274
                    is_visible_in_grid,
275
                    is_filterable_in_grid,
276
                    search_weight,
277
                    additional_data
278
               FROM catalog_eav_attribute
279
              WHERE attribute_id = :attribute_id',
280
        SqlStatements::ATTRIBUTE_BY_ATTRIBUTE_CODE =>
281
            'SELECT * FROM eav_attribute WHERE attribute_code = :attribute_code',
282
        SqlStatements::ATTRIBUTE_LABEL_BY_ATTRIBUTE_CODE_AND_STORE_ID =>
283
            'SELECT t1.*
284
               FROM eav_attribute_label t1,
285
                    eav_attribute t2
286
              WHERE t2.attribute_code = :attribute_code
287
                AND t1.attribute_id = t2.attribute_id
288
                AND t1.store_id = :store_id',
289
        SqlStatements::ATTRIBUTE_OPTION_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE =>
290
            'SELECT t2.*
291
               FROM eav_attribute t1,
292
                    eav_attribute_option t2,
293
                    eav_attribute_option_value t3
294
              WHERE t1.attribute_code = :attribute_code
295
                AND t3.store_id = :store_id
296
                AND t3.value = :value
297
                AND t2.attribute_id = t1.attribute_id
298
                AND t2.option_id = t3.option_id',
299
        SqlStatements::ATTRIBUTE_OPTION_SWATCH_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE_AND_TYPE =>
300
            'SELECT t3.*
301
               FROM eav_attribute t1,
302
                    eav_attribute_option t2,
303
                    eav_attribute_option_swatch t3
304
              WHERE t1.attribute_code = :attribute_code
305
                AND t3.store_id = :store_id
306
                AND t3.value = :value
307
                AND t3.type = :type
308
                AND t2.attribute_id = t1.attribute_id
309
                AND t2.option_id = t3.option_id',
310
        SqlStatements::CATALOG_ATTRIBUTE_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID =>
311
            'SELECT t2.*
312
               FROM eav_attribute t1
313
         INNER JOIN catalog_eav_attribute t2
314
              WHERE t1.attribute_code = :attribute_code
315
                AND t1.entity_type_id = :entity_type_id
316
                AND t2.attribute_id = t1.attribute_id',
317
        SqlStatements::ENTITY_ATTRIBUTE_BY_ATTRIBUTE_ID_AND_ATTRIBUTE_SET_ID_AND_ATTRIBUTE_GROUP_ID =>
318
            'SELECT *
319
               FROM eav_entity_attribute
320
              WHERE entity_type_id = :entity_type_id
321
                AND attribute_id = :attribute_id
322
                AND attribute_set_id = :attribute_set_id
323
                AND attribute_group_id = :attribute_group_id',
324
        SqlStatements::CREATE_ATTRIBUTE =>
325
            'INSERT
326
               INTO eav_attribute
327
                    (entity_type_id,
328
                     attribute_code,
329
                     attribute_model,
330
                     backend_model,
331
                     backend_type,
332
                     backend_table,
333
                     frontend_model,
334
                     frontend_input,
335
                     frontend_label,
336
                     frontend_class,
337
                     source_model,
338
                     is_required,
339
                     is_user_defined,
340
                     default_value,
341
                     is_unique,
342
                     note)
343
             VALUES (:entity_type_id,
344
                     :attribute_code,
345
                     :attribute_model,
346
                     :backend_model,
347
                     :backend_type,
348
                     :backend_table,
349
                     :frontend_model,
350
                     :frontend_input,
351
                     :frontend_label,
352
                     :frontend_class,
353
                     :source_model,
354
                     :is_required,
355
                     :is_user_defined,
356
                     :default_value,
357
                     :is_unique,
358
                     :note)',
359
        SqlStatements::CREATE_ENTITY_ATTRIBUTE =>
360
            'INSERT
361
               INTO eav_entity_attribute
362
                    (entity_type_id,
363
                     attribute_id,
364
                     attribute_set_id,
365
                     attribute_group_id,
366
                     sort_order)
367
             VALUES (:entity_type_id,
368
                     :attribute_id,
369
                     :attribute_set_id,
370
                     :attribute_group_id,
371
                     :sort_order)',
372
        SqlStatements::CREATE_ATTRIBUTE_LABEL =>
373
            'INSERT
374
               INTO eav_attribute_label
375
                    (attribute_id,
376
                     store_id,
377
                     value)
378
             VALUES (:attribute_id,
379
                     :store_id,
380
                     :value)',
381
        SqlStatements::CREATE_ATTRIBUTE_OPTION =>
382
            'INSERT
383
               INTO eav_attribute_option
384
                    (attribute_id,
385
                     sort_order)
386
             VALUES (:attribute_id,
387
                     :sort_order)',
388
        SqlStatements::CREATE_ATTRIBUTE_OPTION_VALUE =>
389
            'INSERT
390
               INTO eav_attribute_option_value
391
                    (option_id,
392
                     store_id,
393
                     value)
394
             VALUES (:option_id,
395
                     :store_id,
396
                     :value)',
397
        SqlStatements::CREATE_ATTRIBUTE_OPTION_SWATCH =>
398
            'INSERT
399
               INTO eav_attribute_option_swatch
400
                    (option_id,
401
                     store_id,
402
                     value,
403
                     type)
404
             VALUES (:option_id,
405
                    :store_id,
406
                    :value,
407
                    :type)',
408
        SqlStatements::CREATE_CATALOG_ATTRIBUTE =>
409
            'INSERT
410
               INTO catalog_eav_attribute
411
                    (attribute_id,
412
                     frontend_input_renderer,
413
                     is_global,
414
                     is_visible,
415
                     is_searchable,
416
                     is_filterable,
417
                     is_comparable,
418
                     is_visible_on_front,
419
                     is_html_allowed_on_front,
420
                     is_used_for_price_rules,
421
                     is_filterable_in_search,
422
                      used_in_product_listing,
423
                     used_for_sort_by,
424
                     apply_to,
425
                     is_visible_in_advanced_search,
426
                     position,
427
                     is_wysiwyg_enabled,
428
                     is_used_for_promo_rules,
429
                     is_required_in_admin_store,
430
                     is_used_in_grid,
431
                     is_visible_in_grid,
432
                     is_filterable_in_grid,
433
                     search_weight,
434
                     additional_data)
435
             VALUES (:attribute_id,
436
                     :frontend_input_renderer,
437
                     :is_global,
438
                     :is_visible,
439
                     :is_searchable,
440
                     :is_filterable,
441
                     :is_comparable,
442
                     :is_visible_on_front,
443
                     :is_html_allowed_on_front,
444
                     :is_used_for_price_rules,
445
                     :is_filterable_in_search,
446
                     :used_in_product_listing,
447
                     :used_for_sort_by,
448
                     :apply_to,
449
                     :is_visible_in_advanced_search,
450
                     :position,
451
                     :is_wysiwyg_enabled,
452
                     :is_used_for_promo_rules,
453
                     :is_required_in_admin_store,
454
                     :is_used_in_grid,
455
                     :is_visible_in_grid,
456
                     :is_filterable_in_grid,
457
                     :search_weight,
458
                     :additional_data)',
459
        SqlStatements::UPDATE_ATTRIBUTE =>
460
            'UPDATE eav_attribute
461
                SET entity_type_id = :entity_type_id,
462
                    attribute_code = :attribute_code,
463
                    attribute_model = :attribute_model,
464
                    backend_model = :backend_model,
465
                    backend_type = :backend_type,
466
                    backend_table = :backend_table,
467
                    frontend_model = :frontend_model,
468
                    frontend_input = :frontend_input,
469
                    frontend_label = :frontend_label,
470
                    frontend_class = :frontend_class,
471
                    source_model = :source_model,
472
                    is_required = :is_required,
473
                    is_user_defined = :is_user_defined,
474
                    default_value = :default_value,
475
                    is_unique = :is_unique,
476
                    note = :note
477
              WHERE attribute_id = :attribute_id',
478
        SqlStatements::UPDATE_CATALOG_ATTRIBUTE =>
479
            'UPDATE catalog_eav_attribute
480
                SET frontend_input_renderer = :frontend_input_renderer,
481
                    is_global = :is_global,
482
                    is_visible = :is_visible,
483
                    is_searchable = :is_searchable,
484
                    is_filterable = :is_filterable,
485
                    is_comparable = :is_comparable,
486
                    is_visible_on_front = :is_visible_on_front,
487
                    is_html_allowed_on_front = :is_html_allowed_on_front,
488
                    is_used_for_price_rules = :is_used_for_price_rules,
489
                    is_filterable_in_search = :is_filterable_in_search,
490
                    used_in_product_listing = :used_in_product_listing,
491
                    used_for_sort_by = :used_for_sort_by,
492
                    apply_to = :apply_to,
493
                    is_visible_in_advanced_search = :is_visible_in_advanced_search,
494
                    position = :position,
495
                    is_wysiwyg_enabled = :is_wysiwyg_enabled,
496
                    is_used_for_promo_rules = :is_used_for_promo_rules,
497
                    is_required_in_admin_store = :is_required_in_admin_store,
498
                    is_used_in_grid = :is_used_in_grid,
499
                    is_visible_in_grid = :is_visible_in_grid,
500
                    is_filterable_in_grid = :is_filterable_in_grid,
501
                    search_weight = :search_weight,
502
                    additional_data = :additional_data
503
              WHERE attribute_id = :attribute_id',
504
        SqlStatements::UPDATE_ENTITY_ATTRIBUTE =>
505
            'UPDATE eav_entity_attribute
506
                SET entity_type_id = :entity_type_id,
507
                    attribute_id = :attribute_id,
508
                    attribute_set_id = :attribute_set_id,
509
                    attribute_group_id = :attribute_group_id,
510
                    sort_order = :sort_order
511
              WHERE entity_attribute_id = :entity_attribute_id',
512
        SqlStatements::UPDATE_ATTRIBUTE_LABEL =>
513
            'UPDATE eav_attribute_label
514
                SET attribute_id = :attribute_id,
515
                    store_id = :store_id,
516
                    value = :value
517
              WHERE attribute_label_id = :attribute_label_id',
518
        SqlStatements::UPDATE_ATTRIBUTE_OPTION =>
519
            'UPDATE eav_attribute_option
520
                SET attribute_id = :attribute_id,
521
                    sort_order = :sort_order
522
              WHERE option_id = :option_id',
523
        SqlStatements::UPDATE_ATTRIBUTE_OPTION_VALUE =>
524
            'UPDATE eav_attribute_option_value
525
                SET option_id = :option_id,
526
                    store_id = :store_id,
527
                    value = :value
528
              WHERE value_id = :value_id',
529
        SqlStatements::UPDATE_ATTRIBUTE_OPTION_SWATCH =>
530
            'UPDATE eav_attribute_option_swatch
531
                SET option_id = :option_id,
532
                    store_id = :store_id,
533
                    value = :value,
534
                    type = :type
535
              WHERE swatch_id = :swatch_id',
536
        SqlStatements::DELETE_ATTRIBUTE =>
537
            'DELETE FROM eav_attribute WHERE attribute_id = :attribute_id',
538
        SqlStatements::DELETE_ENTITY_ATTRIBUTE =>
539
            'DELETE FROM eav_entity_attribute WHERE entity_attribute_id = :entity_attribute_id',
540
        SqlStatements::DELETE_ATTRIBUTE_LABEL =>
541
            'DELETE FROM eav_attribute_label WHERE attribute_label_id = :attribute_label_id',
542
        SqlStatements::DELETE_ATTRIBUTE_OPTION =>
543
            'DELETE FROM eav_attribute_option WHERE option_id = :option_id',
544
        SqlStatements::DELETE_ATTRIBUTE_OPTION_VALUE =>
545
            'DELETE FROM eav_attribute_option_value WHERE value_id = :value_id',
546
        SqlStatements::DELETE_ATTRIBUTE_OPTION_SWATCH =>
547
            'DELETE FROM eav_attribute_option_swatch WHERE swatch_id = :swatch_id',
548
        SqlStatements::DELETE_CATALOG_ATTRIBUTE =>
549
            'DELETE FROM catalog_eav_attribute WHERE attribute_id = :attribute_id',
550
        SqlStatements::DELETE_ATTRIBUTE_BY_ATTRIBUTE_CODE =>
551
            'DELETE FROM eav_attribute WHERE attribute_code = :attribute_code'
552
    );
553
554
    /**
555
     * Initialize the the SQL statements.
556
     */
557
    public function __construct()
558
    {
559
560
        // call the parent constructor
561
        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\Util...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...
562
563
        // merge the class statements
564
        foreach ($this->statements as $key => $statement) {
565
            $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...
566
        }
567
    }
568
}
569