|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\GroupedProduct\Setup; |
| 7 | + |
| 8 | +use Magento\Catalog\Model\ResourceModel\Product\Relation; |
| 9 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 10 | +use Magento\Framework\Setup\ModuleContextInterface; |
| 11 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 12 | +use Magento\Framework\Setup\UpgradeDataInterface; |
| 13 | +use Magento\GroupedProduct\Model\ResourceModel\Product\Link; |
| 14 | + |
| 15 | +class UpgradeData implements UpgradeDataInterface |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var Relation |
| 19 | + */ |
| 20 | + private $relationProcessor; |
| 21 | + |
| 22 | + /** |
| 23 | + * UpgradeData constructor |
| 24 | + * @param Relation $relationProcessor |
| 25 | + */ |
| 26 | + public function __construct(Relation $relationProcessor) |
| 27 | + { |
| 28 | + $this->relationProcessor = $relationProcessor; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * {@inheritdoc} |
| 33 | + */ |
| 34 | + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) |
| 35 | + { |
| 36 | + $setup->startSetup(); |
| 37 | + |
| 38 | + if (version_compare($context->getVersion(), '2.0.1', '<')) { |
| 39 | + $connection = $setup->getConnection(); |
| 40 | + $select = $connection->select() |
| 41 | + ->from( |
| 42 | + $this->relationProcessor->getTable('catalog_product_link'), |
| 43 | + ['product_id', 'linked_product_id'] |
| 44 | + ) |
| 45 | + ->where('link_type_id = ?', Link::LINK_TYPE_GROUPED); |
| 46 | + |
| 47 | + $connection->query( |
| 48 | + $connection->insertFromSelect( |
| 49 | + $select, $this->relationProcessor->getMainTable(), |
| 50 | + ['parent_id', 'child_id'], |
| 51 | + AdapterInterface::INSERT_IGNORE |
| 52 | + ) |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + $setup->endSetup(); |
| 57 | + } |
| 58 | +} |
0 commit comments