Skip to content

Commit e2e4d7e

Browse files
author
Kopylova,Olga(okopylova)
committed
Merge pull request #261 from magento-ogre/PR_Branch_ES
[Phoenix Media - Ogres] Accept Phoenix Media Sprint 4 code for Elastic Search
2 parents f3b0daf + c77771f commit e2e4d7e

File tree

5 files changed

+165
-3
lines changed

5 files changed

+165
-3
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Indexer;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\Indexer\IndexStructureInterface;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
class IndexStructureFactory
14+
{
15+
/**
16+
* Object Manager instance
17+
*
18+
* @var ObjectManagerInterface
19+
*/
20+
protected $objectManager = null;
21+
22+
/**
23+
* Instance name to create
24+
*
25+
* @var string
26+
*/
27+
protected $structures = null;
28+
29+
/**
30+
* @var ScopeConfigInterface
31+
*/
32+
private $scopeConfig;
33+
34+
/**
35+
* Configuration path by which current indexer handler stored
36+
*
37+
* @var string
38+
*/
39+
private $configPath;
40+
41+
/**
42+
* Factory constructor
43+
*
44+
* @param ObjectManagerInterface $objectManager
45+
* @param ScopeConfigInterface $scopeConfig
46+
* @param string $configPath
47+
* @param string[] $structures
48+
*/
49+
public function __construct(
50+
ObjectManagerInterface $objectManager,
51+
ScopeConfigInterface $scopeConfig,
52+
$configPath,
53+
array $structures = []
54+
) {
55+
$this->objectManager = $objectManager;
56+
$this->scopeConfig = $scopeConfig;
57+
$this->configPath = $configPath;
58+
$this->structures = $structures;
59+
}
60+
61+
/**
62+
* Create index structure
63+
*
64+
* @param array $data
65+
* @return IndexStructureInterface
66+
*/
67+
public function create(array $data = [])
68+
{
69+
$currentStructure = $this->scopeConfig->getValue($this->configPath, ScopeInterface::SCOPE_STORE);
70+
if (!isset($this->structures[$currentStructure])) {
71+
throw new \LogicException(
72+
'There is no such index structure: ' . $currentStructure
73+
);
74+
}
75+
$indexStructure = $this->objectManager->create($this->structures[$currentStructure], $data);
76+
77+
if (!$indexStructure instanceof IndexStructureInterface) {
78+
throw new \InvalidArgumentException(
79+
$indexStructure . ' doesn\'t implement \Magento\Framework\Indexer\IndexStructureInterface'
80+
);
81+
}
82+
83+
return $indexStructure;
84+
}
85+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Indexer;
7+
8+
use Magento\Framework\Indexer\IndexStructureInterface;
9+
10+
class IndexStructureProxy implements IndexStructureInterface
11+
{
12+
/**
13+
* @var IndexStructureInterface
14+
*/
15+
private $indexStructureEntity;
16+
17+
/**
18+
* @var IndexStructureFactory
19+
*/
20+
private $indexStructureFactory;
21+
22+
/**
23+
* @param IndexStructureFactory $indexStructureFactory
24+
*/
25+
public function __construct(
26+
IndexStructureFactory $indexStructureFactory
27+
) {
28+
$this->indexStructureFactory = $indexStructureFactory;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function delete(
35+
$index,
36+
array $dimensions = []
37+
) {
38+
return $this->getEntity()->delete($index, $dimensions);
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function create(
45+
$index,
46+
array $fields,
47+
array $dimensions = []
48+
) {
49+
return $this->getEntity()->create($index, $fields, $dimensions);
50+
}
51+
52+
/**
53+
* Get instance of current index structure
54+
*
55+
* @return IndexStructureInterface
56+
*/
57+
private function getEntity()
58+
{
59+
if (empty($this->indexStructureEntity)) {
60+
$this->indexStructureEntity = $this->indexStructureFactory->create();
61+
}
62+
return $this->indexStructureEntity;
63+
}
64+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\ResourceConnection;
1010
use Magento\Framework\DB\Adapter\AdapterInterface;
1111
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
12+
use Magento\Framework\Indexer\IndexStructureInterface;
1213
use Magento\Framework\Search\Request\Dimension;
1314
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
1415
use Magento\Framework\Indexer\SaveHandler\Batch;
@@ -17,7 +18,7 @@
1718
class IndexerHandler implements IndexerInterface
1819
{
1920
/**
20-
* @var IndexStructure
21+
* @var IndexStructureInterface
2122
*/
2223
private $indexStructure;
2324

@@ -57,7 +58,7 @@ class IndexerHandler implements IndexerInterface
5758
private $indexScopeResolver;
5859

5960
/**
60-
* @param IndexStructure $indexStructure
61+
* @param IndexStructureInterface $indexStructure
6162
* @param ResourceConnection $resource
6263
* @param Config $eavConfig
6364
* @param Batch $batch
@@ -66,7 +67,7 @@ class IndexerHandler implements IndexerInterface
6667
* @param int $batchSize
6768
*/
6869
public function __construct(
69-
IndexStructure $indexStructure,
70+
IndexStructureInterface $indexStructure,
7071
ResourceConnection $resource,
7172
Config $eavConfig,
7273
Batch $batch,

app/code/Magento/CatalogSearch/etc/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
</argument>
2020
</arguments>
2121
</type>
22+
<type name="Magento\CatalogSearch\Model\Indexer\IndexStructureFactory">
23+
<arguments>
24+
<argument name="configPath" xsi:type="const">Magento\CatalogSearch\Model\ResourceModel\EngineInterface::CONFIG_ENGINE_PATH</argument>
25+
<argument name="structures" xsi:type="array">
26+
<item name="mysql" xsi:type="string">Magento\CatalogSearch\Model\Indexer\IndexStructure</item>
27+
</argument>
28+
</arguments>
29+
</type>
30+
<preference for="Magento\Framework\Indexer\IndexStructureInterface" type="Magento\CatalogSearch\Model\Indexer\IndexStructureProxy" />
2231
<type name="Magento\Framework\Search\Adapter\Mysql\Aggregation\DataProviderContainer">
2332
<arguments>
2433
<argument name="dataProviders" xsi:type="array">

dev/tests/static/testsuite/Magento/Test/Legacy/_files/words_ce.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@
4949
<path>dev/tests/api-functional/testsuite/Magento/Webapi/Routing/RequestIdOverrideTest.php</path>
5050
<word>overriden</word>
5151
</item>
52+
<item>
53+
<path>composer.lock</path>
54+
</item>
5255
</whitelist>
5356
</config>

0 commit comments

Comments
 (0)