|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Elasticsearch\Framework\Indexing; |
|
4
|
|
|
|
|
5
|
|
|
use OpenSearch\Client; |
|
6
|
|
|
use Shopware\Core\Framework\Context; |
|
7
|
|
|
use Shopware\Core\Framework\Feature; |
|
8
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
9
|
|
|
use Shopware\Elasticsearch\Framework\ElasticsearchHelper; |
|
10
|
|
|
use Shopware\Elasticsearch\Framework\ElasticsearchLanguageProvider; |
|
11
|
|
|
use Shopware\Elasticsearch\Framework\ElasticsearchRegistry; |
|
12
|
|
|
|
|
13
|
|
|
#[Package('core')] |
|
14
|
|
|
class IndexMappingUpdater |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @internal |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct( |
|
20
|
|
|
private readonly ElasticsearchRegistry $registry, |
|
21
|
|
|
private readonly ElasticsearchHelper $elasticsearchHelper, |
|
22
|
|
|
private readonly ElasticsearchLanguageProvider $languageProvider, |
|
23
|
|
|
private readonly Client $client, |
|
24
|
|
|
private readonly IndexMappingProvider $indexMappingProvider |
|
25
|
|
|
) { |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function update(Context $context): void |
|
29
|
|
|
{ |
|
30
|
|
|
if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) { |
|
31
|
|
|
$languages = $this->languageProvider->getLanguages($context); |
|
32
|
|
|
|
|
33
|
|
|
foreach ($this->registry->getDefinitions() as $definition) { |
|
34
|
|
|
foreach ($languages as $language) { |
|
35
|
|
|
$indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition(), $language->getId()); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$this->client->indices()->putMapping([ |
|
38
|
|
|
'index' => $indexName, |
|
39
|
|
|
'body' => $this->indexMappingProvider->build($definition, $context), |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
foreach ($this->registry->getDefinitions() as $definition) { |
|
48
|
|
|
$indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition()); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$this->client->indices()->putMapping([ |
|
51
|
|
|
'index' => $indexName, |
|
52
|
|
|
'body' => $this->indexMappingProvider->build($definition, $context), |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.