Code Duplication    Length = 15-25 lines in 6 locations

Bootstrap/Update.php 6 locations

@@ 520-534 (lines=15) @@
517
    /**
518
      * Create index by articleID in s_plugin_connect_product_to_categories table.
519
      */
520
    private function addProductToCategoryIndex()
521
    {
522
        if (version_compare($this->version, '1.1.7', '<=')) {
523
            try {
524
                $this->db->query('ALTER TABLE s_plugin_connect_product_to_categories ADD INDEX article_id(articleID)');
525
            } catch (\Exception $e) {
526
                // ignore it if exists
527
                $this->logger->write(
528
                    true,
529
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
530
                    $e->getMessage()
531
                );
532
            }
533
        }
534
    }
535
536
    private function addShopIdToConnectCategories()
537
    {
@@ 579-595 (lines=17) @@
576
        }
577
    }
578
579
    private function changeExportStatusToVarchar()
580
    {
581
        if (version_compare($this->version, '1.1.8', '<=')) {
582
            try {
583
                $this->db->query('ALTER TABLE s_plugin_connect_items MODIFY export_status varchar(255)');
584
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX IDX_revision (revision)');
585
                $this->db->query('ALTER TABLE s_plugin_connect_items ADD INDEX IDX_status (export_status)');
586
            } catch (\Exception $e) {
587
                // ignore it if exists
588
                $this->logger->write(
589
                    true,
590
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
591
                    $e->getMessage()
592
                );
593
            }
594
        }
595
    }
596
597
    private function addArticleRelationsTable()
598
    {
@@ 597-611 (lines=15) @@
594
        }
595
    }
596
597
    private function addArticleRelationsTable()
598
    {
599
        if (version_compare($this->version, '1.1.8', '<=')) {
600
            try {
601
                $this->db->query(
602
                    'CREATE TABLE IF NOT EXISTS `s_plugin_connect_article_relations` (
603
                  `id` int(11) NOT NULL AUTO_INCREMENT,
604
                  `article_id` int(11) unsigned NOT NULL,
605
                  `shop_id` int(11) NOT NULL,
606
                  `related_article_local_id` int(11) NOT NULL,
607
                  `relationship_type` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
608
                  PRIMARY KEY (`id`),
609
                  UNIQUE KEY `relations` (`article_id`, `shop_id`, `related_article_local_id`, `relationship_type`),
610
                  CONSTRAINT s_plugin_connect_article_relations_fk_article_id FOREIGN KEY (article_id) REFERENCES s_articles (id) ON DELETE CASCADE
611
                  ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'
612
                );
613
            } catch (\Exception $e) {
614
                // ignore it if exists
@@ 624-641 (lines=18) @@
621
        }
622
    }
623
624
    private function addOverwriteMainImage()
625
    {
626
        if (version_compare($this->version, '1.1.8', '<=')) {
627
            try {
628
                if (!$this->existsConfig('overwriteProductMainImage')) {
629
                    $this->db->query('INSERT INTO `s_plugin_connect_config` (`name`, `value`, `groupName`) VALUES ("overwriteProductMainImage", "1", "import")');
630
                }
631
                $this->db->query('ALTER TABLE `s_plugin_connect_items` ADD COLUMN `update_main_image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL');
632
            } catch (\Exception $e) {
633
                // ignore it if exists
634
                $this->logger->write(
635
                    true,
636
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
637
                    $e->getMessage()
638
                );
639
            }
640
        }
641
    }
642
643
    private function changeGroupNameImportSettings()
644
    {
@@ 643-657 (lines=15) @@
640
        }
641
    }
642
643
    private function changeGroupNameImportSettings()
644
    {
645
        if (version_compare($this->version, '1.1.11', '<=')) {
646
            try {
647
                $this->db->query('UPDATE `s_plugin_connect_config` SET `groupName` = "import" WHERE `groupName` = "general" AND `name` IN ("createCategoriesAutomatically", "activateProductsAutomatically", "createUnitsAutomatically",
648
                                            "detailShopInfo", "checkoutShopInfo", "showShippingCostsSeparately")');
649
            } catch (\Exception $e) {
650
                $this->logger->write(
651
                    true,
652
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
653
                    $e->getMessage()
654
                );
655
            }
656
        }
657
    }
658
659
    private function addArticleDetailsForeignKey()
660
    {
@@ 659-683 (lines=25) @@
656
        }
657
    }
658
659
    private function addArticleDetailsForeignKey()
660
    {
661
        if (version_compare($this->version, '1.1.11', '<=')) {
662
            try {
663
                $this->db->query('
664
                ALTER TABLE s_plugin_connect_items
665
                ADD FOREIGN KEY (`article_detail_id`) REFERENCES s_articles_details (id) ON DELETE SET NULL
666
                ');
667
            } catch (\Exception $e) {
668
                $this->logger->write(
669
                    true,
670
                    sprintf('An error occurred during update to version %s stacktrace: %s', $this->version, $e->getTraceAsString()),
671
                    $e->getMessage()
672
                );
673
            }
674
        }
675
    }
676
677
    /**
678
     * @param string $configName
679
     * @return bool
680
     */
681
    private function existsConfig($configName) {
682
        $stmt = $this->db->prepare('SELECT * FROM s_plugin_connect_config WHERE `name` = ?');
683
        $stmt->execute([$configName]);
684
685
        return $stmt->fetch() !== false;
686
    }