-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #710 from magento-dragons/pr-22-develop
Fixed issues: - MAGETWO-58174: When catalog is being indexed it should index in place or leverage an index alias so store can still function during a long index run - MAGETWO-61829: SOAP/REST tests fail on develop branch but builds are green - MAGETWO-62387: Travis Build Fail - 2.2.0 - MAGETWO-59990: Disable child product doesn't work in Configurable variations grid - MAGETWO-58701: memory_limit issue after running customer_grid indexer - MAGETWO-61159: Configurable Product visible on the Category when options are Out of Stock and Disabled
- Loading branch information
Showing
43 changed files
with
1,361 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/code/Magento/CatalogSearch/Model/Indexer/IndexSwitcherInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSearch\Model\Indexer; | ||
|
||
/** | ||
* Provides a functionality to replace main index with its temporary representation | ||
*/ | ||
interface IndexSwitcherInterface | ||
{ | ||
/** | ||
* Switch current index with temporary index | ||
* | ||
* It will drop current index table and rename temporary index table to the current index table. | ||
* | ||
* @param array $dimensions | ||
* @return void | ||
*/ | ||
public function switchIndex(array $dimensions); | ||
} |
100 changes: 100 additions & 0 deletions
100
app/code/Magento/CatalogSearch/Model/Indexer/IndexSwitcherProxy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\CatalogSearch\Model\Indexer; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Proxy for adapter-specific index switcher | ||
*/ | ||
class IndexSwitcherProxy implements IndexSwitcherInterface | ||
{ | ||
/** | ||
* Object Manager instance | ||
* | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager = null; | ||
|
||
/** | ||
* Instance name to create | ||
* | ||
* @var string | ||
*/ | ||
private $handlers; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* Configuration path by which current indexer handler stored | ||
* | ||
* @var string | ||
*/ | ||
private $configPath; | ||
|
||
/** | ||
* Factory constructor | ||
* | ||
* @param ObjectManagerInterface $objectManager | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param string $configPath | ||
* @param string[] $handlers | ||
*/ | ||
public function __construct( | ||
ObjectManagerInterface $objectManager, | ||
ScopeConfigInterface $scopeConfig, | ||
$configPath, | ||
array $handlers = [] | ||
) { | ||
$this->objectManager = $objectManager; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->configPath = $configPath; | ||
$this->handlers = $handlers; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* As index switcher is an optional part of the search SPI, it may be not defined by a search engine. | ||
* It is especially reasonable for search engines with pre-defined indexes declaration (like old SOLR and Sphinx) | ||
* which cannot create temporary indexes on the fly. | ||
* That's the reason why this method do nothing for the case | ||
* when switcher is not defined for a specific search engine. | ||
*/ | ||
public function switchIndex(array $dimensions) | ||
{ | ||
$currentHandler = $this->scopeConfig->getValue($this->configPath, ScopeInterface::SCOPE_STORE); | ||
if (!isset($this->handlers[$currentHandler])) { | ||
return; | ||
} | ||
$this->create($currentHandler)->switchIndex($dimensions); | ||
} | ||
|
||
/** | ||
* Create indexer handler | ||
* | ||
* @param string $handler | ||
* @return IndexSwitcherInterface | ||
*/ | ||
private function create($handler) | ||
{ | ||
$indexSwitcher = $this->objectManager->create($this->handlers[$handler]); | ||
|
||
if (!$indexSwitcher instanceof IndexSwitcherInterface) { | ||
throw new \InvalidArgumentException( | ||
$handler . ' index switcher doesn\'t implement ' . IndexSwitcherInterface::class | ||
); | ||
} | ||
|
||
return $indexSwitcher; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/code/Magento/CatalogSearch/Model/Indexer/Scope/IndexSwitcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSearch\Model\Indexer\Scope; | ||
|
||
use Magento\CatalogSearch\Model\Indexer\IndexSwitcherInterface; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\Search\Request\IndexScopeResolverInterface; | ||
|
||
/** | ||
* Provides a functionality to replace main index with its temporary representation | ||
*/ | ||
class IndexSwitcher implements IndexSwitcherInterface | ||
{ | ||
/** | ||
* @var Resource | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @var ScopeProxy | ||
*/ | ||
private $resolver; | ||
|
||
/** | ||
* @var State | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* @param ResourceConnection $resource | ||
* @param IndexScopeResolverInterface $indexScopeResolver | ||
* @param State $state | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resource, | ||
IndexScopeResolverInterface $indexScopeResolver, | ||
State $state | ||
) { | ||
$this->resource = $resource; | ||
$this->resolver = $indexScopeResolver; | ||
$this->state = $state; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @throws IndexTableNotExistException | ||
*/ | ||
public function switchIndex(array $dimensions) | ||
{ | ||
if (State::USE_TEMPORARY_INDEX === $this->state->getState()) { | ||
$index = \Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID; | ||
|
||
$temporalIndexTable = $this->resolver->resolve($index, $dimensions); | ||
if (!$this->resource->getConnection()->isTableExists($temporalIndexTable)) { | ||
throw new IndexTableNotExistException( | ||
__( | ||
"Temporary table for index $index doesn't exist," | ||
. " which is inconsistent with state of scope resolver" | ||
) | ||
); | ||
} | ||
|
||
$this->state->useRegularIndex(); | ||
$tableName = $this->resolver->resolve($index, $dimensions); | ||
if ($this->resource->getConnection()->isTableExists($tableName)) { | ||
$this->resource->getConnection()->dropTable($tableName); | ||
} | ||
|
||
$this->resource->getConnection()->renameTable($temporalIndexTable, $tableName); | ||
$this->state->useTemporaryIndex(); | ||
} | ||
} | ||
} |
Oops, something went wrong.