Completed
Pull Request — master (#422)
by Jonas
05:22
created

Update   C

Complexity

Total Complexity 74

Size/Duplication

Total Lines 537
Duplicated Lines 19.55 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 105
loc 537
rs 5.5244
c 0
b 0
f 0
wmc 74
lcom 1
cbo 1

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
B run() 0 27 1
A reVerifySDK() 0 10 1
A createExportedFlag() 0 16 2
A removeRedirectMenu() 0 10 3
A updateConnectAttribute() 0 19 3
B addConnectDescriptionElement() 0 27 3
B updateProductDescriptionSetting() 0 39 5
A createUpdateAdditionalDescriptionColumn() 0 14 3
A createDynamicStreamTable() 0 15 2
B addOrderStatus() 0 35 4
C fixExportDescriptionSettings() 0 37 8
D fixMarketplaceUrl() 8 38 10
A addIndexToChangeTable() 0 9 2
A removeDuplicatedMenuItems() 0 18 4
A addConnectItemsIndex() 18 18 3
B createRemoteToLocalCategoriesTable() 0 34 4
A recreateRemoteCategoriesAndProductAssignments() 15 15 3
A setDefaultConfigForUpdateOrderStatus() 15 15 3
A addProductToCategoryIndex() 15 15 3
A addShopIdToConnectCategories() 18 18 3
A addOverwriteMainImage() 16 16 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Update often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Update, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Bootstrap;
9
10
use Shopware\CustomModels\Connect\Attribute;
11
use Shopware\Components\Model\ModelManager;
12
use Enlight_Components_Db_Adapter_Pdo_Mysql as Pdo;
13
use Shopware\Models\Attribute\Configuration;
14
use Shopware\Models\Order\Status;
15
use ShopwarePlugins\Connect\Components\ProductQuery\BaseProductQuery;
16
use ShopwarePlugins\Connect\Components\Utils\ConnectOrderUtil;
17
use ShopwarePlugins\Connect\Components\Logger;
18
19
/**
20
 * Updates existing versions of the plugin
21
 *
22
 * Class Update
23
 * @package ShopwarePlugins\Connect\Bootstrap
24
 */
25
class Update
26
{
27
    /**
28
     * @var \Shopware_Plugins_Backend_SwagConnect_Bootstrap
29
     */
30
    protected $bootstrap;
31
32
    /**
33
     * @var Pdo
34
     */
35
    protected $db;
36
37
    /**
38
     * @var ModelManager
39
     */
40
    protected $modelManager;
41
42
    /**
43
     * @var string
44
     */
45
    protected $version;
46
47
    /**
48
     * @var Logger
49
     */
50
    private $logger;
51
52
    /**
53
     * Setup constructor.
54
     * @param \Shopware_Plugins_Backend_SwagConnect_Bootstrap $bootstrap
55
     * @param ModelManager $modelManager
56
     * @param Pdo $db
57
     * @param $version
58
     * @param Logger|null $logger
59
     */
60
    public function __construct(
61
        \Shopware_Plugins_Backend_SwagConnect_Bootstrap $bootstrap,
62
        ModelManager $modelManager,
63
        Pdo $db,
64
        Logger $logger,
65
        $version
66
    ) {
67
        $this->bootstrap = $bootstrap;
68
        $this->modelManager = $modelManager;
69
        $this->db = $db;
70
        $this->logger = $logger;
71
        $this->version = $version;
72
    }
73
74
    public function run()
75
    {
76
        // Force an SDK re-verify
77
        $this->reVerifySDK();
78
79
        $this->createExportedFlag();
80
        $this->removeRedirectMenu();
81
        $this->updateConnectAttribute();
82
        $this->addConnectDescriptionElement();
83
        $this->updateProductDescriptionSetting();
84
        $this->createUpdateAdditionalDescriptionColumn();
85
        $this->createDynamicStreamTable();
86
        $this->addOrderStatus();
87
        $this->fixExportDescriptionSettings();
88
        $this->fixMarketplaceUrl();
89
        $this->addIndexToChangeTable();
90
        $this->removeDuplicatedMenuItems();
91
        $this->addConnectItemsIndex();
92
        $this->createRemoteToLocalCategoriesTable();
93
        $this->recreateRemoteCategoriesAndProductAssignments();
94
        $this->setDefaultConfigForUpdateOrderStatus();
95
        $this->addShopIdToConnectCategories();
96
        $this->addProductToCategoryIndex();
97
        $this->addOverwriteMainImage();
98
99
        return true;
100
    }
101
102
    /**
103
     * Forces the SDK to re-verify the API key
104
     */
105
    public function reVerifySDK()
106
    {
107
        $this->db->query('
108
            UPDATE sw_connect_shop_config
109
            SET s_config = ?
110
            WHERE s_shop = "_last_update_"
111
            LIMIT 1; ',
112
            [time() - 8 * 60 * 60 * 24]
113
        );
114
    }
115
116
    private function createExportedFlag()
117
    {
118
        if (version_compare($this->version, '1.0.1', '<=')) {
119
            $this->db->query('
120
                ALTER TABLE `s_plugin_connect_items`
121
                ADD COLUMN `exported` TINYINT(1) DEFAULT 0
122
            ');
123
124
            $this->db->query('
125
                UPDATE `s_plugin_connect_items`
126
                SET `exported` = 1
127
                WHERE (`export_status` = ? OR `export_status` = ? OR `export_status` = ?) AND `shop_id` IS NULL',
128
                [Attribute::STATUS_INSERT, Attribute::STATUS_UPDATE, Attribute::STATUS_SYNCED]
129
            );
130
        }
131
    }
132
133
    private function removeRedirectMenu()
134
    {
135
        if (version_compare($this->version, '1.0.4', '<=')) {
136
            $connectItem = $this->bootstrap->Menu()->findOneBy(['label' => 'Open Connect', 'action' => '']);
137
            if ($connectItem) {
138
                $this->modelManager->remove($connectItem);
139
                $this->modelManager->flush();
140
            }
141
        }
142
    }
143
144
    private function updateConnectAttribute()
145
    {
146
        if (version_compare($this->version, '1.0.6', '<=')) {
147
            $result = $this->db->query("SELECT value FROM s_plugin_connect_config WHERE name = 'connectAttribute'");
148
            $row = $result->fetch();
149
            $attr = 19;
150
            if ($row) {
151
                $attr = $row['value'];
152
            }
153
154
            $this->db->query('
155
                    UPDATE `s_articles_attributes` 
156
                    SET `connect_reference` = `attr' . $attr . '` 
157
                    WHERE connect_reference IS NULL;
158
                ');
159
160
            $this->db->query("DELETE FROM s_plugin_connect_config WHERE name = 'connectAttribute'");
161
        }
162
    }
163
164
    private function addConnectDescriptionElement()
165
    {
166
        if (version_compare($this->version, '1.0.9', '<=')) {
167
            $tableName = $this->modelManager->getClassMetadata('Shopware\Models\Attribute\Article')->getTableName();
168
            $columnName = 'connect_product_description';
169
170
            $repo = $this->modelManager->getRepository('Shopware\Models\Attribute\Configuration');
171
            $element = $repo->findOneBy([
172
                'tableName' => $tableName,
173
                'columnName' => $columnName,
174
            ]);
175
176
            if (!$element) {
177
                $element = new Configuration();
178
                $element->setTableName($tableName);
179
                $element->setColumnName($columnName);
180
            }
181
182
            $element->setColumnType('html');
183
            $element->setTranslatable(true);
184
            $element->setLabel('Connect Beschreibung');
185
            $element->setDisplayInBackend(true);
186
187
            $this->modelManager->persist($element);
188
            $this->modelManager->flush();
189
        }
190
    }
191
192
    private function updateProductDescriptionSetting()
193
    {
194
        if (version_compare($this->version, '1.0.9', '<=')) {
195
            //migrates to the new export settings
196
            $result = $this->db->query("SELECT `value` FROM s_plugin_connect_config WHERE name = 'alternateDescriptionField'");
197
            $row = $result->fetch();
198
199
            if ($row) {
200
                $mapper = [
201
                    'a.description' => BaseProductQuery::SHORT_DESCRIPTION_FIELD,
202
                    'a.descriptionLong' => BaseProductQuery::LONG_DESCRIPTION_FIELD,
203
                    'attribute.connectProductDescription' => BaseProductQuery::CONNECT_DESCRIPTION_FIELD,
204
                ];
205
206
                if ($name = $mapper[$row['value']]) {
207
                    $result = $this->db->query("SELECT `id` FROM s_plugin_connect_config WHERE name = '$name'");
208
                    $row = $result->fetch();
209
210
                    $id = null;
211
                    if (isset($row['id'])) {
212
                        $id = $row['id'];
213
                    }
214
215
                    $this->db->query(
216
                        "REPLACE INTO `s_plugin_connect_config`
217
                        (`id`, `name`, `value`, `shopId`, `groupName`)
218
                        VALUES
219
                        (?, ?, 1, null, 'export')",
220
                        [$id, $name]
221
                    );
222
                }
223
            }
224
225
            $this->db->query("
226
                ALTER TABLE `s_plugin_connect_items`
227
                ADD `update_additional_description` VARCHAR(255) NULL DEFAULT 'inherit' AFTER `update_short_description`;
228
            ");
229
        }
230
    }
231
232
    private function createUpdateAdditionalDescriptionColumn()
233
    {
234
        // for some reason update_additional_description column is missing in 1.0.11
235
        if (version_compare($this->version, '1.0.11', '<=')) {
236
            try {
237
                $this->db->query("
238
                        ALTER TABLE `s_plugin_connect_items`
239
                        ADD `update_additional_description` VARCHAR(255) NULL DEFAULT 'inherit' AFTER `update_short_description`;
240
                    ");
241
            } catch (\Exception $e) {
242
                // ignore it if the column already exists
243
            }
244
        }
245
    }
246
247
    private function createDynamicStreamTable()
248
    {
249
        if (version_compare($this->version, '1.0.12', '<=')) {
250
            $query = "CREATE TABLE IF NOT EXISTS `s_plugin_connect_streams_relation` (
251
                `stream_id` int(11) unsigned NOT NULL,
252
                `article_id` int(11) unsigned NOT NULL,
253
                `deleted` int(1) NOT NULL DEFAULT '0',
254
                UNIQUE KEY `stream_id` (`stream_id`,`article_id`),
255
                CONSTRAINT s_plugin_connect_streams_selection_fk_stream_id FOREIGN KEY (stream_id) REFERENCES s_product_streams (id) ON DELETE CASCADE,
256
                CONSTRAINT s_plugin_connect_streams_selection_fk_article_id FOREIGN KEY (article_id) REFERENCES s_articles (id) ON DELETE CASCADE
257
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
258
259
            $this->db->exec($query);
260
        }
261
    }
262
263
    private function addOrderStatus()
264
    {
265
        if (version_compare($this->version, '1.0.12', '<=')) {
266
            $query = $this->modelManager->getRepository('Shopware\Models\Order\Status')->createQueryBuilder('s');
267
            $query->select('MAX(s.id)');
268
            $result = $query->getQuery()->getOneOrNullResult();
269
270
            if (count($result) > 0) {
271
                $currentId = (int) reset($result);
272
            } else {
273
                $currentId = 0;
274
            }
275
276
            $name = ConnectOrderUtil::ORDER_STATUS_ERROR;
277
            $group = Status::GROUP_STATE;
278
279
            $isExists = $this->db->query('
280
                SELECT `id` FROM `s_core_states`
281
                WHERE `name` = ? AND `group` = ?
282
                ', [$name, $group]
283
            )->fetch();
284
285
            if ($isExists) {
286
                return;
287
            }
288
289
            ++$currentId;
290
            $this->db->query('
291
                INSERT INTO `s_core_states`
292
                (`id`, `name`, `description`, `position`, `group`, `mail`)
293
                VALUES (?, ?, ?, ?, ?, ?)
294
                ', [$currentId, $name, 'SC error', $currentId, $group, 0]
295
            );
296
        }
297
    }
298
299
    /**
300
     * Replace longDescriptionField and shortDescription values,
301
     * because of wrong snippets in previous versions.
302
     *
303
     * ExtJs view show longDescription label, but the value was stored as shortDescription
304
     */
305
    private function fixExportDescriptionSettings()
306
    {
307
        if (version_compare($this->version, '1.0.12', '<=')) {
308
            $rows = $this->db->fetchPairs(
309
                'SELECT `name`, `value` FROM s_plugin_connect_config WHERE name = ? OR name = ?',
310
                ['longDescriptionField', 'shortDescriptionField']
311
            );
312
313
            if (!array_key_exists('longDescriptionField', $rows) || !array_key_exists('shortDescriptionField', $rows)) {
314
                return;
315
            }
316
317
            if (($rows['longDescriptionField'] == 1 && $rows['shortDescriptionField'] == 1)
318
                || ($rows['longDescriptionField'] == 0 && $rows['shortDescriptionField'] == 0)) {
319
                return;
320
            }
321
322
            $newValues = [
323
                'longDescriptionField' => $rows['shortDescriptionField'],
324
                'shortDescriptionField' => $rows['longDescriptionField'],
325
            ];
326
327
            $this->db->query('
328
                UPDATE `s_plugin_connect_config`
329
                SET `value` = ?
330
                WHERE `name` = ?',
331
                [$newValues['longDescriptionField'], 'longDescriptionField']
332
            );
333
334
            $this->db->query('
335
                UPDATE `s_plugin_connect_config`
336
                SET `value` = ?
337
                WHERE `name` = ?',
338
                [$newValues['shortDescriptionField'], 'shortDescriptionField']
339
            );
340
        }
341
    }
342
343
    private function fixMarketplaceUrl()
344
    {
345
        if (version_compare($this->version, '1.0.12', '<=')) {
346
            $repo = $this->modelManager->getRepository('Shopware\Models\Config\Form');
347
            /** @var \Shopware\Models\Config\Form $form */
348
            $form = $repo->findOneBy([
349
                'name' => 'SwagConnect',
350
            ]);
351
352
            if (!$form) {
353
                return;
354
            }
355
356
            /** @var \Shopware\Models\Config\Element $element */
357
            foreach ($form->getElements() as $element) {
358
                if ($element->getName() != 'connectDebugHost') {
359
                    continue;
360
                }
361
362 View Code Duplication
                if (strlen($element->getValue()) > 0 && strpos($element->getValue(), 'sn.') === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363
                    $element->setValue('sn.' . $element->getValue());
364
                    $this->modelManager->persist($element);
365
                }
366
367
                $values = $element->getValues();
368
                if (count($values) > 0) {
369
                    /** @var \Shopware\Models\Config\Value $element */
370
                    $value = $values[0];
371 View Code Duplication
                    if (strlen($value->getValue()) > 0 && strpos($value->getValue(), 'sn.') === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
372
                        $value->setValue('sn.' . $value->getValue());
373
                        $this->modelManager->persist($value);
374
                    }
375
                }
376
377
                $this->modelManager->flush();
378
            }
379
        }
380
    }
381
382
    private function addIndexToChangeTable()
383
    {
384
        if (version_compare($this->version, '1.0.16', '<=')) {
385
            $this->db->query('
386
              ALTER TABLE `sw_connect_change`
387
              ADD INDEX `c_operation` (`c_operation`)
388
             ');
389
        }
390
    }
391
392
    /**
393
     * In some cases Connect main menu was duplicated
394
     * when shop is connected to SEM project. All not needed menu items must be removed.
395
     */
396
    private function removeDuplicatedMenuItems()
397
    {
398
        if (version_compare($this->version, '1.0.16', '<=')) {
399
            $mainMenuItems = $this->bootstrap->Menu()->findBy([
400
                'class' => Menu::CONNECT_CLASS,
401
                'parent' => null,
402
            ], ['id' => 'ASC']);
403
404
            foreach (array_slice($mainMenuItems, 1) as $menuItem) {
405
                foreach ($menuItem->getChildren() as $children) {
406
                    $this->modelManager->remove($children);
407
                }
408
409
                $this->modelManager->remove($menuItem);
410
            }
411
            $this->modelManager->flush();
412
        }
413
    }
414
415
    /**
416
     * Create most used indexes in s_plugin_connect_items table.
417
     */
418 View Code Duplication
    private function addConnectItemsIndex()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
419
    {
420
        if (version_compare($this->version, '1.1.1', '<=')) {
421
            try {
422
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX stream(shop_id, stream)');
423
                $this->db->query('ALTER TABLE s_plugin_connect_items MODIFY group_id VARCHAR(64)');
424
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX source_id (source_id, shop_id)');
425
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX group_id (group_id, shop_id)');
426
            } catch (\Exception $e) {
427
                // ignore it if exists
428
                $this->logger->write(
429
                    true,
430
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
431
                    $e->getMessage()
432
                );
433
            }
434
        }
435
    }
436
437
    /**
438
     * Create the mapping table between connect remote categories and local categories.
439
     */
440
    private function createRemoteToLocalCategoriesTable()
441
    {
442
        if (version_compare($this->version, '1.1.3', '<=')) {
443
            try {
444
                $this->db->query('CREATE TABLE IF NOT EXISTS `s_plugin_connect_categories_to_local_categories` (
445
                  `remote_category_id` int(11) NOT NULL,
446
                  `local_category_id` int(11) unsigned NOT NULL,
447
                  PRIMARY KEY (`remote_category_id`, `local_category_id`),
448
                  CONSTRAINT s_plugin_connect_remote_categories_fk_remote_category_id FOREIGN KEY (remote_category_id) REFERENCES s_plugin_connect_categories (id) ON DELETE CASCADE,
449
                  CONSTRAINT s_plugin_connect_remote_categories_fk_local_category_id FOREIGN KEY (local_category_id) REFERENCES s_categories (id) ON DELETE CASCADE
450
                  ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'
451
                );
452
                $result = $this->db->query('SELECT pcc.id, pcc.local_category_id
453
                                FROM s_plugin_connect_categories pcc
454
                                WHERE pcc.local_category_id IS NOT NULL');
455
456
                while ($row = $result->fetch()) {
457
                    $this->db->query(
458
                        'INSERT INTO `s_plugin_connect_categories_to_local_categories`
459
                        (`remote_category_id`, `local_category_id`)
460
                        VALUES (?, ?)',
461
                        [$row['id'],$row['local_category_id']]
462
                    );
463
                }
464
            } catch (\Exception $e) {
465
                // ignore it if exists
466
                $this->logger->write(
467
                    true,
468
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
469
                    $e->getMessage()
470
                );
471
            }
472
        }
473
    }
474
475 View Code Duplication
    private function recreateRemoteCategoriesAndProductAssignments()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
476
    {
477
        if (version_compare($this->version, '1.1.4', '<=')) {
478
            try {
479
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`) VALUES ("recreateConnectCategories", "0")');
480
            } catch (\Exception $e) {
481
                // ignore it if exists
482
                $this->logger->write(
483
                    true,
484
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
485
                    $e->getMessage()
486
                );
487
            }
488
        }
489
    }
490
491 View Code Duplication
    private function setDefaultConfigForUpdateOrderStatus()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
492
    {
493
        if (version_compare($this->version, '1.1.7', '<=')) {
494
            try {
495
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`, `groupName`) VALUES ("updateOrderStatus", "0", "import")');
496
            } catch (\Exception $e) {
497
                // ignore it if exists
498
                $this->logger->write(
499
                    true,
500
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
501
                    $e->getMessage()
502
                );
503
            }
504
        }
505
    }
506
  
507
  /**
508
     * Create index by articleID in s_plugin_connect_product_to_categories table.
509
     */
510 View Code Duplication
    private function addProductToCategoryIndex()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
511
    {
512
        if (version_compare($this->version, '1.1.7', '<=')) {
513
            try {
514
                $this->db->query('ALTER TABLE s_plugin_connect_product_to_categories ADD INDEX article_id(articleID)');
515
            } catch (\Exception $e) {
516
                // ignore it if exists
517
                $this->logger->write(
518
                    true,
519
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
520
                    $e->getMessage()
521
                );
522
            }
523
        }
524
    }
525
526 View Code Duplication
    private function addShopIdToConnectCategories()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
527
    {
528
        if (version_compare($this->version, '1.1.7', '<=')) {
529
            try {
530
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`) VALUES ("addShopIdToConnectCategories", "0")');
531
                $this->db->query('ALTER TABLE s_plugin_connect_categories ADD COLUMN `shop_id` int(11) NULL');
532
                $this->db->query('ALTER TABLE s_plugin_connect_categories DROP INDEX scuk_category_key');
533
                $this->db->query('ALTER TABLE s_plugin_connect_categories ADD UNIQUE KEY `scuk_connect_category_for_shop_id` (`category_key`,`shop_id`)');
534
            } catch (\Exception $e) {
535
                // ignore it if exists
536
                $this->logger->write(
537
                    true,
538
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
539
                    $e->getMessage()
540
                );
541
            } 
542
        }
543
    }
544
545 View Code Duplication
    private function addOverwriteMainImage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
546
    {
547
        if (version_compare($this->version, '1.1.8', '<=')) {
548
            try {
549
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`, `groupName`) VALUES ("overwriteProductMainImage", "1", "import")');
550
                $this->db->query('ALTER TABLE `s_plugin_connect_items` ADD COLUMN `update_main_image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL');
551
            } catch (\Exception $e) {
552
                // ignore it if exists
553
                $this->logger->write(
554
                    true,
555
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
556
                    $e->getMessage()
557
                );
558
            }
559
        }
560
    }
561
}
562