Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EnableSegmentation.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
8 
11 
18 {
22  private $moduleDataSetup;
23 
29  public function __construct(
30  ModuleDataSetupInterface $moduleDataSetup
31  ) {
32  $this->moduleDataSetup = $moduleDataSetup;
33  }
34 
38  public function apply()
39  {
40  $this->moduleDataSetup->startSetup();
41  $setup = $this->moduleDataSetup;
42 
43  $catalogCategoryProductIndexColumns = array_keys(
44  $setup->getConnection()->describeTable($setup->getTable('catalog_category_product_index'))
45  );
46  $storeSelect = $setup->getConnection()->select()->from($setup->getTable('store'))->where('store_id > 0');
47  foreach ($setup->getConnection()->fetchAll($storeSelect) as $store) {
48  $catalogCategoryProductIndexSelect = $setup->getConnection()->select()
49  ->from(
50  $setup->getTable('catalog_category_product_index')
51  )->where(
52  'store_id = ?',
53  $store['store_id']
54  );
55  $indexTable = $setup->getTable('catalog_category_product_index') .
56  '_' .
58  $store['store_id'];
59  $setup->getConnection()->query(
60  $setup->getConnection()->insertFromSelect(
61  $catalogCategoryProductIndexSelect,
62  $indexTable,
63  $catalogCategoryProductIndexColumns,
65  )
66  );
67  }
68  $setup->getConnection()->delete($setup->getTable('catalog_category_product_index'));
69  $setup->getConnection()->delete($setup->getTable('catalog_category_product_index_replica'));
70  $setup->getConnection()->delete($setup->getTable('catalog_category_product_index_tmp'));
71 
72  $this->moduleDataSetup->endSetup();
73  }
74 
78  public static function getDependencies()
79  {
80  return [];
81  }
82 
86  public function getAliases()
87  {
88  return [];
89  }
90 }
__construct(ModuleDataSetupInterface $moduleDataSetup)
$setup
Definition: trigger.php:12