Skip to content

Commit 80f08d4

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3-develop' into MAGETWO-89776
2 parents ba5e17c + 2f6cb7d commit 80f08d4

File tree

22 files changed

+347
-232
lines changed

22 files changed

+347
-232
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,6 @@ public function execute()
115115
return $this;
116116
}
117117

118-
/**
119-
* Return select for remove unnecessary data
120-
*
121-
* @return \Magento\Framework\DB\Select
122-
*
123-
* @deprecated Not used anymore.
124-
* @see clearCurrentTable()
125-
*/
126-
protected function getSelectUnnecessaryData()
127-
{
128-
return $this->connection->select()->from(
129-
$this->getMainTable(),
130-
[]
131-
)->joinLeft(
132-
['t' => $this->getMainTable()],
133-
$this->getMainTable() .
134-
'.category_id = t.category_id AND ' .
135-
$this->getMainTable() .
136-
'.store_id = t.store_id AND ' .
137-
$this->getMainTable() .
138-
'.product_id = t.product_id',
139-
[]
140-
)->where(
141-
't.category_id IS NULL'
142-
);
143-
}
144-
145-
/**
146-
* Remove unnecessary data
147-
*
148-
* @return void
149-
*
150-
* @deprecated Not used anymore.
151-
* @see clearCurrentTable()
152-
*/
153-
protected function removeUnnecessaryData()
154-
{
155-
//Called for backward compatibility.
156-
$this->getSelectUnnecessaryData();
157-
}
158-
159118
/**
160119
* Publish data from tmp to index
161120
*
@@ -254,8 +213,6 @@ private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSe
254213
)
255214
);
256215
$this->publishData();
257-
//Called for backward compatibility.
258-
$this->removeUnnecessaryData();
259216
}
260217
}
261218
}

app/code/Magento/Catalog/view/frontend/templates/product/view/addtocart.phtml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,10 @@
4040
</div>
4141
</div>
4242
<?php endif; ?>
43-
<?php if ($block->isRedirectToCartEnabled()) : ?>
44-
<script type="text/x-magento-init">
45-
{
46-
"#product_addtocart_form": {
47-
"Magento_Catalog/product/view/validation": {
48-
"radioCheckboxClosest": ".nested"
49-
}
50-
}
51-
}
52-
</script>
53-
<?php else : ?>
5443
<script type="text/x-magento-init">
5544
{
5645
"#product_addtocart_form": {
5746
"Magento_Catalog/js/validate-product": {}
5847
}
5948
}
6049
</script>
61-
<?php endif; ?>

app/code/Magento/CatalogSearch/Model/Fulltext.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ protected function _construct()
7373
* Reset search results cache
7474
*
7575
* @return $this
76+
* @deprecated Not used anymore
77+
* @see \Magento\CatalogSearch\Model\ResourceModel\Fulltext::resetSearchResultsByStore
7678
*/
7779
public function resetSearchResults()
7880
{

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
namespace Magento\CatalogSearch\Model\Indexer;
77

88
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\FullFactory;
9-
use Magento\CatalogSearch\Model\Indexer\Scope\State;
9+
use Magento\CatalogSearch\Model\Indexer\Scope\StateFactory;
1010
use Magento\CatalogSearch\Model\ResourceModel\Fulltext as FulltextResource;
11-
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\Search\Request\Config as SearchRequestConfig;
13-
use Magento\Framework\Search\Request\DimensionFactory;
14-
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Framework\Indexer\Dimension\DimensionProviderInterface;
12+
use Magento\Store\Model\StoreDimensionProvider;
1513

1614
/**
1715
* Provide functionality for Fulltext Search indexing.
1816
*
1917
* @api
2018
* @since 100.0.2
2119
*/
22-
class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
20+
class Fulltext implements
21+
\Magento\Framework\Indexer\ActionInterface,
22+
\Magento\Framework\Mview\ActionInterface,
23+
\Magento\Framework\Indexer\Dimension\DimensionalIndexerInterface
2324
{
2425
/**
2526
* Indexer ID in configuration
@@ -36,16 +37,6 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
3637
*/
3738
private $indexerHandlerFactory;
3839

39-
/**
40-
* @var StoreManagerInterface
41-
*/
42-
private $storeManager;
43-
44-
/**
45-
* @var \Magento\Framework\Search\Request\DimensionFactory
46-
*/
47-
private $dimensionFactory;
48-
4940
/**
5041
* @var \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full
5142
*/
@@ -56,11 +47,6 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
5647
*/
5748
private $fulltextResource;
5849

59-
/**
60-
* @var \Magento\Framework\Search\Request\Config
61-
*/
62-
private $searchRequestConfig;
63-
6450
/**
6551
* @var IndexSwitcherInterface
6652
*/
@@ -71,90 +57,97 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
7157
*/
7258
private $indexScopeState;
7359

60+
/**
61+
* @var DimensionProviderInterface
62+
*/
63+
private $dimensionProvider;
64+
7465
/**
7566
* @param FullFactory $fullActionFactory
7667
* @param IndexerHandlerFactory $indexerHandlerFactory
77-
* @param StoreManagerInterface $storeManager
78-
* @param DimensionFactory $dimensionFactory
7968
* @param FulltextResource $fulltextResource
80-
* @param SearchRequestConfig $searchRequestConfig
8169
* @param array $data
8270
* @param IndexSwitcherInterface $indexSwitcher
83-
* @param Scope\State $indexScopeState
71+
* @param StateFactory $indexScopeStateFactory
72+
* @param DimensionProviderInterface $dimensionProvider
8473
*/
8574
public function __construct(
8675
FullFactory $fullActionFactory,
8776
IndexerHandlerFactory $indexerHandlerFactory,
88-
StoreManagerInterface $storeManager,
89-
DimensionFactory $dimensionFactory,
9077
FulltextResource $fulltextResource,
91-
SearchRequestConfig $searchRequestConfig,
92-
array $data,
93-
IndexSwitcherInterface $indexSwitcher = null,
94-
State $indexScopeState = null
78+
IndexSwitcherInterface $indexSwitcher,
79+
StateFactory $indexScopeStateFactory,
80+
DimensionProviderInterface $dimensionProvider,
81+
array $data
9582
) {
9683
$this->fullAction = $fullActionFactory->create(['data' => $data]);
9784
$this->indexerHandlerFactory = $indexerHandlerFactory;
98-
$this->storeManager = $storeManager;
99-
$this->dimensionFactory = $dimensionFactory;
10085
$this->fulltextResource = $fulltextResource;
101-
$this->searchRequestConfig = $searchRequestConfig;
10286
$this->data = $data;
103-
if (null === $indexSwitcher) {
104-
$indexSwitcher = ObjectManager::getInstance()->get(IndexSwitcherInterface::class);
105-
}
106-
if (null === $indexScopeState) {
107-
$indexScopeState = ObjectManager::getInstance()->get(State::class);
108-
}
10987
$this->indexSwitcher = $indexSwitcher;
110-
$this->indexScopeState = $indexScopeState;
88+
$this->indexScopeState = $indexScopeStateFactory->create();
89+
$this->dimensionProvider = $dimensionProvider;
11190
}
11291

11392
/**
11493
* Execute materialization on ids entities
11594
*
116-
* @param int[] $ids
95+
* @param int[] $entityIds
11796
* @return void
97+
* @throws \InvalidArgumentException
11898
*/
119-
public function execute($ids)
99+
public function execute($entityIds)
120100
{
121-
$storeIds = array_keys($this->storeManager->getStores());
122-
/** @var IndexerHandler $saveHandler */
123-
$saveHandler = $this->indexerHandlerFactory->create([
124-
'data' => $this->data
125-
]);
126-
foreach ($storeIds as $storeId) {
127-
$dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
128-
$productIds = array_unique(array_merge($ids, $this->fulltextResource->getRelationsByChild($ids)));
129-
$saveHandler->deleteIndex([$dimension], new \ArrayObject($productIds));
130-
$saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId, $ids));
101+
foreach ($this->dimensionProvider->getIterator() as $dimension) {
102+
$this->executeByDimension($dimension, new \ArrayIterator($entityIds));
131103
}
132104
}
133105

134106
/**
135-
* Execute full indexation
136-
*
137-
* @return void
107+
* {@inheritdoc}
108+
* @throws \InvalidArgumentException
138109
*/
139-
public function executeFull()
110+
public function executeByDimension(array $dimensions, \Traversable $entityIds = null)
140111
{
141-
$storeIds = array_keys($this->storeManager->getStores());
142-
/** @var IndexerHandler $saveHandler */
112+
if (count($dimensions) > 1 || !isset($dimensions[StoreDimensionProvider::DIMENSION_NAME])) {
113+
throw new \InvalidArgumentException('Indexer "' . self::INDEXER_ID . '" support only Store dimension');
114+
}
115+
$storeId = $dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue();
143116
$saveHandler = $this->indexerHandlerFactory->create([
144117
'data' => $this->data
145118
]);
146-
foreach ($storeIds as $storeId) {
147-
$dimensions = [$this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId])];
148-
$this->indexScopeState->useTemporaryIndex();
149119

120+
if (null === $entityIds) {
121+
$this->indexScopeState->useTemporaryIndex();
150122
$saveHandler->cleanIndex($dimensions);
151123
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId));
152124

153125
$this->indexSwitcher->switchIndex($dimensions);
154126
$this->indexScopeState->useRegularIndex();
127+
128+
$this->fulltextResource->resetSearchResultsByStore($storeId);
129+
} else {
130+
// internal implementation works only with array
131+
$entityIds = iterator_to_array($entityIds);
132+
$productIds = array_unique(
133+
array_merge($entityIds, $this->fulltextResource->getRelationsByChild($entityIds))
134+
);
135+
$saveHandler->deleteIndex($dimensions, new \ArrayIterator($productIds));
136+
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId, $entityIds));
137+
}
138+
}
139+
140+
/**
141+
* Execute full indexation
142+
*
143+
* @return void
144+
* @throws \InvalidArgumentException
145+
*/
146+
public function executeFull()
147+
{
148+
foreach ($this->dimensionProvider->getIterator() as $dimension) {
149+
$this->executeByDimension($dimension);
155150
}
156-
$this->fulltextResource->resetSearchResults();
157-
$this->searchRequestConfig->reset();
158151
}
159152

160153
/**

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ protected function _construct()
6262
* Reset search results
6363
*
6464
* @return $this
65+
* @deprecated Not used anymore
66+
* @see Fulltext::resetSearchResultsByStore
6567
*/
6668
public function resetSearchResults()
6769
{
@@ -71,6 +73,25 @@ public function resetSearchResults()
7173
return $this;
7274
}
7375

76+
/**
77+
* Reset search results by store
78+
*
79+
* @param int $storeId
80+
* @return $this
81+
*/
82+
public function resetSearchResultsByStore($storeId)
83+
{
84+
$storeId = (int) $storeId;
85+
$connection = $this->getConnection();
86+
$connection->update(
87+
$this->getTable('search_query'),
88+
['is_processed' => 0],
89+
['is_processed != ?' => 0, 'store_id = ?' => $storeId]
90+
);
91+
$this->_eventManager->dispatch('catalogsearch_reset_search_result', ['store_id' => $storeId]);
92+
return $this;
93+
}
94+
7495
/**
7596
* Retrieve product relations by children.
7697
*

0 commit comments

Comments
 (0)