Completed
Push — master ( 6cf347...95c736 )
by Sebastian
46s queued 19s
created

Update::changeGroupNameImportSettings()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

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