EnableSegmentation.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Catalog\Setup\Patch\Schema;
  8. use Magento\Framework\Setup\SchemaSetupInterface;
  9. use Magento\Framework\Setup\Patch\SchemaPatchInterface;
  10. /**
  11. * Class EnableSegmentation.
  12. *
  13. * @package Magento\Catalog\Setup\Patch\Schema
  14. */
  15. class EnableSegmentation implements SchemaPatchInterface
  16. {
  17. /**
  18. * @var SchemaSetupInterface
  19. */
  20. private $schemaSetup;
  21. /**
  22. * EnableSegmentation constructor.
  23. *
  24. * @param SchemaSetupInterface $schemaSetup
  25. */
  26. public function __construct(
  27. SchemaSetupInterface $schemaSetup
  28. ) {
  29. $this->schemaSetup = $schemaSetup;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function apply()
  35. {
  36. $this->schemaSetup->startSetup();
  37. $setup = $this->schemaSetup;
  38. $storeSelect = $setup->getConnection()->select()->from($setup->getTable('store'))->where('store_id > 0');
  39. foreach ($setup->getConnection()->fetchAll($storeSelect) as $store) {
  40. $indexTable = $setup->getTable('catalog_category_product_index') .
  41. '_' .
  42. \Magento\Store\Model\Store::ENTITY .
  43. $store['store_id'];
  44. if (!$setup->getConnection()->isTableExists($indexTable)) {
  45. $setup->getConnection()->createTable(
  46. $setup->getConnection()->createTableByDdl(
  47. $setup->getTable('catalog_category_product_index'),
  48. $indexTable
  49. )
  50. );
  51. }
  52. if (!$setup->getConnection()->isTableExists($indexTable . '_replica')) {
  53. $setup->getConnection()->createTable(
  54. $setup->getConnection()->createTableByDdl(
  55. $setup->getTable('catalog_category_product_index'),
  56. $indexTable . '_replica'
  57. )
  58. );
  59. }
  60. }
  61. $this->schemaSetup->endSetup();
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public static function getDependencies()
  67. {
  68. return [];
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function getAliases()
  74. {
  75. return [];
  76. }
  77. }