Skip to content

Commit 0e5d0e6

Browse files
slopukhovduhon
authored andcommitted
MAGETWO-93997: [Forwardport] Create commands to set/show dimension modes for indexers
1 parent b5bf9d2 commit 0e5d0e6

File tree

17 files changed

+1028
-326
lines changed

17 files changed

+1028
-326
lines changed

app/code/Magento/Catalog/Console/Command/PriceIndexerDimensionsModeSetCommand.php

Lines changed: 0 additions & 198 deletions
This file was deleted.

app/code/Magento/Catalog/Model/Indexer/Product/Price/DimensionModeConfiguration.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
7-
87
namespace Magento\Catalog\Model\Indexer\Product\Price;
98

109
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -41,6 +40,7 @@ class DimensionModeConfiguration
4140
CustomerGroupDimensionProvider::DIMENSION_NAME
4241
],
4342
];
43+
4444
/**
4545
* @var ScopeConfigInterface
4646
*/
@@ -59,12 +59,23 @@ public function __construct(ScopeConfigInterface $scopeConfig)
5959
$this->scopeConfig = $scopeConfig;
6060
}
6161

62+
/**
63+
* Return dimension modes configuration.
64+
*
65+
* @return array
66+
*/
67+
public function getDimensionModes(): array
68+
{
69+
return $this->modesMapping;
70+
}
71+
6272
/**
6373
* Get names of dimensions which used for provided mode.
6474
* By default return dimensions for current enabled mode
6575
*
6676
* @param string|null $mode
6777
* @return string[]
78+
* @throws \InvalidArgumentException
6879
*/
6980
public function getDimensionConfiguration(string $mode = null): array
7081
{
@@ -82,7 +93,7 @@ public function getDimensionConfiguration(string $mode = null): array
8293
private function getCurrentMode(): string
8394
{
8495
if (null === $this->currentMode) {
85-
$this->currentMode = $this->scopeConfig->getValue(ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE)
96+
$this->currentMode = $this->scopeConfig->getValue(ModeSwitcherConfiguration::XML_PATH_PRICE_DIMENSIONS_MODE)
8697
?: self::DIMENSION_NONE;
8798
}
8899

app/code/Magento/Catalog/Model/Indexer/Product/Price/ModeSwitcher.php

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
use Magento\Framework\Search\Request\Dimension;
1111
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1212
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
13+
use Magento\Indexer\Model\DimensionModes;
14+
use Magento\Indexer\Model\DimensionMode;
1315

1416
/**
1517
* Class to prepare new tables for new indexer mode
1618
*/
17-
class ModeSwitcher
19+
class ModeSwitcher implements \Magento\Indexer\Model\ModeSwitcherInterface
1820
{
19-
const XML_PATH_PRICE_DIMENSIONS_MODE = 'indexer/catalog_product_price/dimensions_mode';
20-
2121
/**
2222
* TableMaintainer
2323
*
@@ -38,15 +38,60 @@ class ModeSwitcher
3838
private $dimensionsArray;
3939

4040
/**
41-
* @param \Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer $tableMaintainer
42-
* @param \Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory $dimensionCollectionFactory
41+
* @var \Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration
42+
*/
43+
private $dimensionModeConfiguration;
44+
45+
/**
46+
* @var ModeSwitcherConfiguration
47+
*/
48+
private $modeSwitcherConfiguration;
49+
50+
/**
51+
* @param TableMaintainer $tableMaintainer
52+
* @param DimensionCollectionFactory $dimensionCollectionFactory
53+
* @param DimensionModeConfiguration $dimensionModeConfiguration
54+
* @param ModeSwitcherConfiguration $modeSwitcherConfiguration
4355
*/
4456
public function __construct(
45-
\Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer $tableMaintainer,
46-
\Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory $dimensionCollectionFactory
57+
TableMaintainer $tableMaintainer,
58+
DimensionCollectionFactory $dimensionCollectionFactory,
59+
DimensionModeConfiguration $dimensionModeConfiguration,
60+
ModeSwitcherConfiguration $modeSwitcherConfiguration
4761
) {
4862
$this->tableMaintainer = $tableMaintainer;
4963
$this->dimensionCollectionFactory = $dimensionCollectionFactory;
64+
$this->dimensionModeConfiguration = $dimensionModeConfiguration;
65+
$this->modeSwitcherConfiguration = $modeSwitcherConfiguration;
66+
}
67+
68+
/**
69+
* @inheritdoc
70+
*/
71+
public function getDimensionModes(): DimensionModes
72+
{
73+
$dimensionsList = [];
74+
foreach ($this->dimensionModeConfiguration->getDimensionModes() as $dimension => $modes) {
75+
$dimensionsList[] = new DimensionMode($dimension, $modes);
76+
}
77+
78+
return new DimensionModes($dimensionsList);
79+
}
80+
81+
/**
82+
* @inheritdoc
83+
*/
84+
public function switchMode(string $currentMode, string $previousMode)
85+
{
86+
//Create new tables and move data
87+
$this->createTables($currentMode);
88+
$this->moveData($currentMode, $previousMode);
89+
90+
//Change config options
91+
$this->modeSwitcherConfiguration->saveMode($currentMode);
92+
93+
//Delete old tables
94+
$this->dropTables($previousMode);
5095
}
5196

5297
/**
@@ -120,7 +165,7 @@ public function dropTables(string $previousMode)
120165
*
121166
* @param string $mode
122167
*
123-
* @return array
168+
* @return \Magento\Framework\Indexer\MultiDimensionProvider
124169
*/
125170
private function getDimensionsArray(string $mode): \Magento\Framework\Indexer\MultiDimensionProvider
126171
{

0 commit comments

Comments
 (0)