Completed
Push — master ( fa0b22...3a2b7d )
by Sven
03:18
created

Update::createUpdateAdditionalDescriptionColumn()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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