Completed
Pull Request — master (#415)
by Jonas
06:56 queued 03:47
created

Update::addConnectItemsIndex()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 6
nop 0
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
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->addArticleRelationsTable();
98
        $this->addOverwriteMainImage();
99
100
        return true;
101
    }
102
103
    /**
104
     * Forces the SDK to re-verify the API key
105
     */
106
    public function reVerifySDK()
107
    {
108
        $this->db->query('
109
            UPDATE sw_connect_shop_config
110
            SET s_config = ?
111
            WHERE s_shop = "_last_update_"
112
            LIMIT 1; ',
113
            [time() - 8 * 60 * 60 * 24]
114
        );
115
    }
116
117
    private function createExportedFlag()
118
    {
119
        if (version_compare($this->version, '1.0.1', '<=')) {
120
            $this->db->query('
121
                ALTER TABLE `s_plugin_connect_items`
122
                ADD COLUMN `exported` TINYINT(1) DEFAULT 0
123
            ');
124
125
            $this->db->query('
126
                UPDATE `s_plugin_connect_items`
127
                SET `exported` = 1
128
                WHERE (`export_status` = ? OR `export_status` = ? OR `export_status` = ?) AND `shop_id` IS NULL',
129
                [Attribute::STATUS_INSERT, Attribute::STATUS_UPDATE, Attribute::STATUS_SYNCED]
130
            );
131
        }
132
    }
133
134
    private function removeRedirectMenu()
135
    {
136
        if (version_compare($this->version, '1.0.4', '<=')) {
137
            $connectItem = $this->bootstrap->Menu()->findOneBy(['label' => 'Open Connect', 'action' => '']);
138
            if ($connectItem) {
139
                $this->modelManager->remove($connectItem);
140
                $this->modelManager->flush();
141
            }
142
        }
143
    }
144
145
    private function updateConnectAttribute()
146
    {
147
        if (version_compare($this->version, '1.0.6', '<=')) {
148
            $result = $this->db->query("SELECT value FROM s_plugin_connect_config WHERE name = 'connectAttribute'");
149
            $row = $result->fetch();
150
            $attr = 19;
151
            if ($row) {
152
                $attr = $row['value'];
153
            }
154
155
            $this->db->query('
156
                    UPDATE `s_articles_attributes` 
157
                    SET `connect_reference` = `attr' . $attr . '` 
158
                    WHERE connect_reference IS NULL;
159
                ');
160
161
            $this->db->query("DELETE FROM s_plugin_connect_config WHERE name = 'connectAttribute'");
162
        }
163
    }
164
165
    private function addConnectDescriptionElement()
166
    {
167
        if (version_compare($this->version, '1.0.9', '<=')) {
168
            $tableName = $this->modelManager->getClassMetadata('Shopware\Models\Attribute\Article')->getTableName();
169
            $columnName = 'connect_product_description';
170
171
            $repo = $this->modelManager->getRepository('Shopware\Models\Attribute\Configuration');
172
            $element = $repo->findOneBy([
173
                'tableName' => $tableName,
174
                'columnName' => $columnName,
175
            ]);
176
177
            if (!$element) {
178
                $element = new Configuration();
179
                $element->setTableName($tableName);
180
                $element->setColumnName($columnName);
181
            }
182
183
            $element->setColumnType('html');
184
            $element->setTranslatable(true);
185
            $element->setLabel('Connect Beschreibung');
186
            $element->setDisplayInBackend(true);
187
188
            $this->modelManager->persist($element);
189
            $this->modelManager->flush();
190
        }
191
    }
192
193
    private function updateProductDescriptionSetting()
194
    {
195
        if (version_compare($this->version, '1.0.9', '<=')) {
196
            //migrates to the new export settings
197
            $result = $this->db->query("SELECT `value` FROM s_plugin_connect_config WHERE name = 'alternateDescriptionField'");
198
            $row = $result->fetch();
199
200
            if ($row) {
201
                $mapper = [
202
                    'a.description' => BaseProductQuery::SHORT_DESCRIPTION_FIELD,
203
                    'a.descriptionLong' => BaseProductQuery::LONG_DESCRIPTION_FIELD,
204
                    'attribute.connectProductDescription' => BaseProductQuery::CONNECT_DESCRIPTION_FIELD,
205
                ];
206
207
                if ($name = $mapper[$row['value']]) {
208
                    $result = $this->db->query("SELECT `id` FROM s_plugin_connect_config WHERE name = '$name'");
209
                    $row = $result->fetch();
210
211
                    $id = null;
212
                    if (isset($row['id'])) {
213
                        $id = $row['id'];
214
                    }
215
216
                    $this->db->query(
217
                        "REPLACE INTO `s_plugin_connect_config`
218
                        (`id`, `name`, `value`, `shopId`, `groupName`)
219
                        VALUES
220
                        (?, ?, 1, null, 'export')",
221
                        [$id, $name]
222
                    );
223
                }
224
            }
225
226
            $this->db->query("
227
                ALTER TABLE `s_plugin_connect_items`
228
                ADD `update_additional_description` VARCHAR(255) NULL DEFAULT 'inherit' AFTER `update_short_description`;
229
            ");
230
        }
231
    }
232
233
    private function createUpdateAdditionalDescriptionColumn()
234
    {
235
        // for some reason update_additional_description column is missing in 1.0.11
236
        if (version_compare($this->version, '1.0.11', '<=')) {
237
            try {
238
                $this->db->query("
239
                        ALTER TABLE `s_plugin_connect_items`
240
                        ADD `update_additional_description` VARCHAR(255) NULL DEFAULT 'inherit' AFTER `update_short_description`;
241
                    ");
242
            } catch (\Exception $e) {
243
                // ignore it if the column already exists
244
            }
245
        }
246
    }
247
248
    private function createDynamicStreamTable()
249
    {
250
        if (version_compare($this->version, '1.0.12', '<=')) {
251
            $query = "CREATE TABLE IF NOT EXISTS `s_plugin_connect_streams_relation` (
252
                `stream_id` int(11) unsigned NOT NULL,
253
                `article_id` int(11) unsigned NOT NULL,
254
                `deleted` int(1) NOT NULL DEFAULT '0',
255
                UNIQUE KEY `stream_id` (`stream_id`,`article_id`),
256
                CONSTRAINT s_plugin_connect_streams_selection_fk_stream_id FOREIGN KEY (stream_id) REFERENCES s_product_streams (id) ON DELETE CASCADE,
257
                CONSTRAINT s_plugin_connect_streams_selection_fk_article_id FOREIGN KEY (article_id) REFERENCES s_articles (id) ON DELETE CASCADE
258
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
259
260
            $this->db->exec($query);
261
        }
262
    }
263
264
    private function addOrderStatus()
265
    {
266
        if (version_compare($this->version, '1.0.12', '<=')) {
267
            $query = $this->modelManager->getRepository('Shopware\Models\Order\Status')->createQueryBuilder('s');
268
            $query->select('MAX(s.id)');
269
            $result = $query->getQuery()->getOneOrNullResult();
270
271
            if (count($result) > 0) {
272
                $currentId = (int) reset($result);
273
            } else {
274
                $currentId = 0;
275
            }
276
277
            $name = ConnectOrderUtil::ORDER_STATUS_ERROR;
278
            $group = Status::GROUP_STATE;
279
280
            $isExists = $this->db->query('
281
                SELECT `id` FROM `s_core_states`
282
                WHERE `name` = ? AND `group` = ?
283
                ', [$name, $group]
284
            )->fetch();
285
286
            if ($isExists) {
287
                return;
288
            }
289
290
            ++$currentId;
291
            $this->db->query('
292
                INSERT INTO `s_core_states`
293
                (`id`, `name`, `description`, `position`, `group`, `mail`)
294
                VALUES (?, ?, ?, ?, ?, ?)
295
                ', [$currentId, $name, 'SC error', $currentId, $group, 0]
296
            );
297
        }
298
    }
299
300
    /**
301
     * Replace longDescriptionField and shortDescription values,
302
     * because of wrong snippets in previous versions.
303
     *
304
     * ExtJs view show longDescription label, but the value was stored as shortDescription
305
     */
306
    private function fixExportDescriptionSettings()
307
    {
308
        if (version_compare($this->version, '1.0.12', '<=')) {
309
            $rows = $this->db->fetchPairs(
310
                'SELECT `name`, `value` FROM s_plugin_connect_config WHERE name = ? OR name = ?',
311
                ['longDescriptionField', 'shortDescriptionField']
312
            );
313
314
            if (!array_key_exists('longDescriptionField', $rows) || !array_key_exists('shortDescriptionField', $rows)) {
315
                return;
316
            }
317
318
            if (($rows['longDescriptionField'] == 1 && $rows['shortDescriptionField'] == 1)
319
                || ($rows['longDescriptionField'] == 0 && $rows['shortDescriptionField'] == 0)) {
320
                return;
321
            }
322
323
            $newValues = [
324
                'longDescriptionField' => $rows['shortDescriptionField'],
325
                'shortDescriptionField' => $rows['longDescriptionField'],
326
            ];
327
328
            $this->db->query('
329
                UPDATE `s_plugin_connect_config`
330
                SET `value` = ?
331
                WHERE `name` = ?',
332
                [$newValues['longDescriptionField'], 'longDescriptionField']
333
            );
334
335
            $this->db->query('
336
                UPDATE `s_plugin_connect_config`
337
                SET `value` = ?
338
                WHERE `name` = ?',
339
                [$newValues['shortDescriptionField'], 'shortDescriptionField']
340
            );
341
        }
342
    }
343
344
    private function fixMarketplaceUrl()
345
    {
346
        if (version_compare($this->version, '1.0.12', '<=')) {
347
            $repo = $this->modelManager->getRepository('Shopware\Models\Config\Form');
348
            /** @var \Shopware\Models\Config\Form $form */
349
            $form = $repo->findOneBy([
350
                'name' => 'SwagConnect',
351
            ]);
352
353
            if (!$form) {
354
                return;
355
            }
356
357
            /** @var \Shopware\Models\Config\Element $element */
358
            foreach ($form->getElements() as $element) {
359
                if ($element->getName() != 'connectDebugHost') {
360
                    continue;
361
                }
362
363 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...
364
                    $element->setValue('sn.' . $element->getValue());
365
                    $this->modelManager->persist($element);
366
                }
367
368
                $values = $element->getValues();
369
                if (count($values) > 0) {
370
                    /** @var \Shopware\Models\Config\Value $element */
371
                    $value = $values[0];
372 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...
373
                        $value->setValue('sn.' . $value->getValue());
374
                        $this->modelManager->persist($value);
375
                    }
376
                }
377
378
                $this->modelManager->flush();
379
            }
380
        }
381
    }
382
383
    private function addIndexToChangeTable()
384
    {
385
        if (version_compare($this->version, '1.0.16', '<=')) {
386
            $this->db->query('
387
              ALTER TABLE `sw_connect_change`
388
              ADD INDEX `c_operation` (`c_operation`)
389
             ');
390
        }
391
    }
392
393
    /**
394
     * In some cases Connect main menu was duplicated
395
     * when shop is connected to SEM project. All not needed menu items must be removed.
396
     */
397
    private function removeDuplicatedMenuItems()
398
    {
399
        if (version_compare($this->version, '1.0.16', '<=')) {
400
            $mainMenuItems = $this->bootstrap->Menu()->findBy([
401
                'class' => Menu::CONNECT_CLASS,
402
                'parent' => null,
403
            ], ['id' => 'ASC']);
404
405
            foreach (array_slice($mainMenuItems, 1) as $menuItem) {
406
                foreach ($menuItem->getChildren() as $children) {
407
                    $this->modelManager->remove($children);
408
                }
409
410
                $this->modelManager->remove($menuItem);
411
            }
412
            $this->modelManager->flush();
413
        }
414
    }
415
416
    /**
417
     * Create most used indexes in s_plugin_connect_items table.
418
     */
419 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...
420
    {
421
        if (version_compare($this->version, '1.1.1', '<=')) {
422
            try {
423
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX stream(shop_id, stream)');
424
                $this->db->query('ALTER TABLE s_plugin_connect_items MODIFY group_id VARCHAR(64)');
425
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX source_id (source_id, shop_id)');
426
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX group_id (group_id, shop_id)');
427
            } catch (\Exception $e) {
428
                // ignore it if exists
429
                $this->logger->write(
430
                    true,
431
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
432
                    $e->getMessage()
433
                );
434
            }
435
        }
436
    }
437
438
    /**
439
     * Create the mapping table between connect remote categories and local categories.
440
     */
441
    private function createRemoteToLocalCategoriesTable()
442
    {
443
        if (version_compare($this->version, '1.1.3', '<=')) {
444
            try {
445
                $this->db->query('CREATE TABLE IF NOT EXISTS `s_plugin_connect_categories_to_local_categories` (
446
                  `remote_category_id` int(11) NOT NULL,
447
                  `local_category_id` int(11) unsigned NOT NULL,
448
                  PRIMARY KEY (`remote_category_id`, `local_category_id`),
449
                  CONSTRAINT s_plugin_connect_remote_categories_fk_remote_category_id FOREIGN KEY (remote_category_id) REFERENCES s_plugin_connect_categories (id) ON DELETE CASCADE,
450
                  CONSTRAINT s_plugin_connect_remote_categories_fk_local_category_id FOREIGN KEY (local_category_id) REFERENCES s_categories (id) ON DELETE CASCADE
451
                  ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'
452
                );
453
                $result = $this->db->query('SELECT pcc.id, pcc.local_category_id
454
                                FROM s_plugin_connect_categories pcc
455
                                WHERE pcc.local_category_id IS NOT NULL');
456
457
                while ($row = $result->fetch()) {
458
                    $this->db->query(
459
                        'INSERT INTO `s_plugin_connect_categories_to_local_categories`
460
                        (`remote_category_id`, `local_category_id`)
461
                        VALUES (?, ?)',
462
                        [$row['id'],$row['local_category_id']]
463
                    );
464
                }
465
            } catch (\Exception $e) {
466
                // ignore it if exists
467
                $this->logger->write(
468
                    true,
469
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
470
                    $e->getMessage()
471
                );
472
            }
473
        }
474
    }
475
476 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...
477
    {
478
        if (version_compare($this->version, '1.1.4', '<=')) {
479
            try {
480
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`) VALUES ("recreateConnectCategories", "0")');
481
            } catch (\Exception $e) {
482
                // ignore it if exists
483
                $this->logger->write(
484
                    true,
485
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
486
                    $e->getMessage()
487
                );
488
            }
489
        }
490
    }
491
492 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...
493
    {
494
        if (version_compare($this->version, '1.1.7', '<=')) {
495
            try {
496
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`, `groupName`) VALUES ("updateOrderStatus", "0", "import")');
497
            } catch (\Exception $e) {
498
                // ignore it if exists
499
                $this->logger->write(
500
                    true,
501
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
502
                    $e->getMessage()
503
                );
504
            }
505
        }
506
    }
507
508
  /**
509
     * Create index by articleID in s_plugin_connect_product_to_categories table.
510
     */
511 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...
512
    {
513
        if (version_compare($this->version, '1.1.7', '<=')) {
514
            try {
515
                $this->db->query('ALTER TABLE s_plugin_connect_product_to_categories ADD INDEX article_id(articleID)');
516
            } catch (\Exception $e) {
517
                // ignore it if exists
518
                $this->logger->write(
519
                    true,
520
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
521
                    $e->getMessage()
522
                );
523
            }
524
        }
525
    }
526
527 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...
528
    {
529
        if (version_compare($this->version, '1.1.7', '<=')) {
530
            try {
531
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`) VALUES ("addShopIdToConnectCategories", "0")');
532
                $this->db->query('ALTER TABLE s_plugin_connect_categories ADD COLUMN `shop_id` int(11) NULL');
533
                $this->db->query('ALTER TABLE s_plugin_connect_categories DROP INDEX scuk_category_key');
534
                $this->db->query('ALTER TABLE s_plugin_connect_categories ADD UNIQUE KEY `scuk_connect_category_for_shop_id` (`category_key`,`shop_id`)');
535
            } catch (\Exception $e) {
536
                // ignore it if exists
537
                $this->logger->write(
538
                    true,
539
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
540
                    $e->getMessage()
541
                );
542
            }
543
        }
544
    }
545
546 View Code Duplication
    private function addArticleRelationsTable()
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...
547
    {
548
        if (version_compare($this->version, '1.1.8', '<=')) {
549
            try {
550
                $this->db->query('CREATE TABLE IF NOT EXISTS `s_plugin_connect_article_relations` (
551
                  `id` int(11) NOT NULL AUTO_INCREMENT,
552
                  `article_id` int(11) unsigned NOT NULL,
553
                  `shop_id` int(11) NOT NULL,
554
                  `related_article_local_id` int(11) NOT NULL,
555
                  `relationship_type` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
556
                  PRIMARY KEY (`id`),
557
                  UNIQUE KEY `relations` (`article_id`, `shop_id`, `related_article_local_id`, `relationship_type`),
558
                  CONSTRAINT s_plugin_connect_article_relations_fk_article_id FOREIGN KEY (article_id) REFERENCES s_articles (id) ON DELETE CASCADE
559
                  ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'
560
                );
561
              } catch (\Exception $e) {
562
                // ignore it if exists
563
                $this->logger->write(
564
                    true,
565
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
566
                    $e->getMessage()
567
                );
568
            }
569
        }
570
    }
571
  
572 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...
573
    {
574
        if (version_compare($this->version, '1.1.8', '<=')) {
575
            try {
576
                $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`, `groupName`) VALUES ("overwriteProductMainImage", "1", "import")');
577
                $this->db->query('ALTER TABLE `s_plugin_connect_items` ADD COLUMN `update_main_image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL');
578
            } catch (\Exception $e) {
579
                // ignore it if exists
580
                $this->logger->write(
581
                    true,
582
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
583
                    $e->getMessage()
584
                );
585
            }
586
        }
587
    }
588
}
589