Skip to content

Commit 4eb9b6e

Browse files
committed
AC-10652::ES 8 Backward compatibility with 2.4.7-beta3 and 2.4.6-p4
1 parent bfc68a8 commit 4eb9b6e

File tree

19 files changed

+99
-1277
lines changed

19 files changed

+99
-1277
lines changed

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7,95 +7,11 @@
77

88
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\BatchDataMapper;
99

10-
use Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface;
11-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider;
12-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface;
13-
use Magento\Elasticsearch\Model\ResourceModel\Index;
14-
1510
/**
16-
* Provide data mapping for categories fields
11+
* @deprecated Handle the Backward Compatibility issue with ES7 and ES8
12+
* @see AC-10652
13+
* phpcs:disable Generic.Files.LineLength.TooLong
1714
*/
18-
class CategoryFieldsProvider implements AdditionalFieldsProviderInterface
15+
class CategoryFieldsProvider extends \Magento\Elasticsearch\ElasticAdapter\Model\Adapter\BatchDataMapper\CategoryFieldsProvider
1916
{
20-
/**
21-
* @var Index
22-
*/
23-
private $resourceIndex;
24-
25-
/**
26-
* @var AttributeProvider
27-
*/
28-
private $attributeAdapterProvider;
29-
30-
/**
31-
* @var ResolverInterface
32-
*/
33-
private $fieldNameResolver;
34-
35-
/**
36-
* @param Index $resourceIndex
37-
* @param AttributeProvider $attributeAdapterProvider
38-
* @param ResolverInterface $fieldNameResolver
39-
*/
40-
public function __construct(
41-
Index $resourceIndex,
42-
AttributeProvider $attributeAdapterProvider,
43-
ResolverInterface $fieldNameResolver
44-
) {
45-
$this->resourceIndex = $resourceIndex;
46-
$this->attributeAdapterProvider = $attributeAdapterProvider;
47-
$this->fieldNameResolver = $fieldNameResolver;
48-
}
49-
50-
/**
51-
* @inheritdoc
52-
*/
53-
public function getFields(array $productIds, $storeId)
54-
{
55-
$categoryData = $this->resourceIndex->getFullCategoryProductIndexData($storeId, $productIds);
56-
57-
$fields = [];
58-
foreach ($productIds as $productId) {
59-
$fields[$productId] = $this->getProductCategoryData($productId, $categoryData);
60-
}
61-
62-
return $fields;
63-
}
64-
65-
/**
66-
* Prepare category index data for product
67-
*
68-
* @param int $productId
69-
* @param array $categoryIndexData
70-
* @return array
71-
*/
72-
private function getProductCategoryData($productId, array $categoryIndexData)
73-
{
74-
$result = [];
75-
76-
if (array_key_exists($productId, $categoryIndexData)) {
77-
$indexData = $categoryIndexData[$productId];
78-
$categoryIds = array_column($indexData, 'id');
79-
80-
if (count($categoryIds)) {
81-
$result = ['category_ids' => $categoryIds];
82-
$positionAttribute = $this->attributeAdapterProvider->getByAttributeCode('position');
83-
$categoryNameAttribute = $this->attributeAdapterProvider->getByAttributeCode('category_name');
84-
foreach ($indexData as $data) {
85-
$categoryPositionKey = $this->fieldNameResolver->getFieldName(
86-
$positionAttribute,
87-
['categoryId' => $data['id']]
88-
);
89-
$categoryNameKey = $this->fieldNameResolver->getFieldName(
90-
$categoryNameAttribute,
91-
['categoryId' => $data['id']]
92-
);
93-
$result[$categoryPositionKey] = $data['position'];
94-
$result[$categoryNameKey] = $data['name'];
95-
}
96-
}
97-
}
98-
99-
return $result;
100-
}
10117
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProviderProxy.php

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,11 @@
55
*/
66
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\BatchDataMapper;
77

8-
use Magento\AdvancedSearch\Model\Client\ClientResolver;
9-
use Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface;
10-
118
/**
12-
* Proxy for data mapping of categories fields
9+
* @deprecated Handle the Backward Compatibility issue with ES7 and ES8
10+
* @see AC-10652
11+
* phpcs:disable Generic.Files.LineLength.TooLong
1312
*/
14-
class CategoryFieldsProviderProxy implements AdditionalFieldsProviderInterface
13+
class CategoryFieldsProviderProxy extends \Magento\Elasticsearch\ElasticAdapter\Model\Adapter\BatchDataMapper\CategoryFieldsProviderProxy
1514
{
16-
/**
17-
* @var ClientResolver
18-
*/
19-
private $clientResolver;
20-
21-
/**
22-
* @var AdditionalFieldsProviderInterface[]
23-
*/
24-
private $categoryFieldsProviders;
25-
26-
/**
27-
* CategoryFieldsProviderProxy constructor.
28-
* @param ClientResolver $clientResolver
29-
* @param AdditionalFieldsProviderInterface[] $categoryFieldsProviders
30-
*/
31-
public function __construct(
32-
ClientResolver $clientResolver,
33-
array $categoryFieldsProviders
34-
) {
35-
$this->clientResolver = $clientResolver;
36-
$this->categoryFieldsProviders = $categoryFieldsProviders;
37-
}
38-
39-
/**
40-
* @return AdditionalFieldsProviderInterface
41-
*/
42-
private function getCategoryFieldsProvider()
43-
{
44-
return $this->categoryFieldsProviders[$this->clientResolver->getCurrentEngine()];
45-
}
46-
47-
/**
48-
* @inheritdoc
49-
*/
50-
public function getFields(array $productIds, $storeId)
51-
{
52-
return $this->getCategoryFieldsProvider()->getFields($productIds, $storeId);
53-
}
5415
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldIndex/Converter.php

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,11 @@
77

88
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex;
99

10-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface;
11-
1210
/**
13-
* Field type converter from internal index type to elastic service.
11+
* @deprecated Handle the Backward Compatibility issue with ES7 and ES8
12+
* @see AC-10652
13+
* phpcs:disable Generic.Files.LineLength.TooLong
1414
*/
15-
class Converter implements ConverterInterface
15+
class Converter extends \Magento\Elasticsearch\ElasticAdapter\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\Converter
1616
{
17-
/**
18-
* Text flags for Elasticsearch index value
19-
*/
20-
private const ES_NO_INDEX = false;
21-
22-
/**
23-
* Text flags for Elasticsearch no analyze index value
24-
*/
25-
private const ES_NO_ANALYZE = false;
26-
27-
/**
28-
* Mapping between internal data types and elastic service.
29-
*
30-
* @var array
31-
*/
32-
private $mapping = [
33-
ConverterInterface::INTERNAL_NO_INDEX_VALUE => self::ES_NO_INDEX,
34-
ConverterInterface::INTERNAL_NO_ANALYZE_VALUE => self::ES_NO_ANALYZE,
35-
];
36-
37-
/**
38-
* Get service field index type for elasticsearch 5.
39-
*
40-
* @param string $internalType
41-
* @return string|boolean
42-
* @throws \DomainException
43-
*/
44-
public function convert(string $internalType)
45-
{
46-
if (!isset($this->mapping[$internalType])) {
47-
throw new \DomainException(sprintf('Unsupported internal field index type: %s', $internalType));
48-
}
49-
return $this->mapping[$internalType];
50-
}
5117
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldIndex/IndexResolver.php

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,11 @@
77

88
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex;
99

10-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter;
11-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ResolverInterface;
12-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface;
13-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface
14-
as FieldTypeConverterInterface;
15-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface
16-
as FieldTypeResolver;
17-
1810
/**
19-
* Field index resolver that provides index type for the attribute in mapping.
20-
* For example, we need to set ‘no’/false in the case when attribute must be present in index data,
21-
* but stay as not indexable.
11+
* @deprecated Handle the Backward Compatibility issue with ES7 and ES8
12+
* @see AC-10652
13+
* phpcs:disable Generic.Files.LineLength.TooLong
2214
*/
23-
class IndexResolver implements ResolverInterface
15+
class IndexResolver extends \Magento\Elasticsearch\ElasticAdapter\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\IndexResolver
2416
{
25-
/**
26-
* @var ConverterInterface
27-
*/
28-
private $converter;
29-
30-
/**
31-
* @var FieldTypeConverterInterface
32-
*/
33-
private $fieldTypeConverter;
34-
35-
/**
36-
* @var FieldTypeResolver
37-
*/
38-
private $fieldTypeResolver;
39-
40-
/**
41-
* @param ConverterInterface $converter
42-
* @param FieldTypeConverterInterface $fieldTypeConverter
43-
* @param FieldTypeResolver $fieldTypeResolver
44-
*/
45-
public function __construct(
46-
ConverterInterface $converter,
47-
FieldTypeConverterInterface $fieldTypeConverter,
48-
FieldTypeResolver $fieldTypeResolver
49-
) {
50-
$this->converter = $converter;
51-
$this->fieldTypeConverter = $fieldTypeConverter;
52-
$this->fieldTypeResolver = $fieldTypeResolver;
53-
}
54-
55-
/**
56-
* @inheritdoc
57-
*/
58-
public function getFieldIndex(AttributeAdapter $attribute)
59-
{
60-
$index = null;
61-
if (!$attribute->isSearchable()
62-
&& !$attribute->isAlwaysIndexable()
63-
&& ($this->isStringServiceFieldType($attribute) || $attribute->isComplexType())
64-
&& !(($attribute->isIntegerType() || $attribute->isBooleanType())
65-
&& !$attribute->isUserDefined())
66-
&& !$attribute->isFloatType()
67-
) {
68-
$index = $this->converter->convert(ConverterInterface::INTERNAL_NO_INDEX_VALUE);
69-
}
70-
71-
return $index;
72-
}
73-
74-
/**
75-
* Check if service field type for field set as 'string'
76-
*
77-
* @param AttributeAdapter $attribute
78-
* @return bool
79-
*/
80-
private function isStringServiceFieldType(AttributeAdapter $attribute): bool
81-
{
82-
$serviceFieldType = $this->fieldTypeResolver->getFieldType($attribute);
83-
$stringTypeKey = $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING);
84-
85-
return $serviceFieldType === $stringTypeKey;
86-
}
8717
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,11 @@
77

88
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType;
99

10-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface;
11-
1210
/**
13-
* Field type converter from internal data types to elastic service.
11+
* @deprecated Handle the Backward Compatibility issue with ES7 and ES8
12+
* @see AC-10652
13+
* phpcs:disable Generic.Files.LineLength.TooLong
1414
*/
15-
class Converter implements ConverterInterface
15+
class Converter extends \Magento\Elasticsearch\ElasticAdapter\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Converter
1616
{
17-
/**#@+
18-
* Text flags for Elasticsearch field types
19-
*/
20-
private const ES_DATA_TYPE_TEXT = 'text';
21-
private const ES_DATA_TYPE_KEYWORD = 'keyword';
22-
private const ES_DATA_TYPE_DOUBLE = 'double';
23-
private const ES_DATA_TYPE_INT = 'integer';
24-
private const ES_DATA_TYPE_DATE = 'date';
25-
/**#@-*/
26-
27-
/**
28-
* Mapping between internal data types and elastic service.
29-
*
30-
* @var array
31-
*/
32-
private $mapping = [
33-
self::INTERNAL_DATA_TYPE_STRING => self::ES_DATA_TYPE_TEXT,
34-
self::INTERNAL_DATA_TYPE_KEYWORD => self::ES_DATA_TYPE_KEYWORD,
35-
self::INTERNAL_DATA_TYPE_FLOAT => self::ES_DATA_TYPE_DOUBLE,
36-
self::INTERNAL_DATA_TYPE_INT => self::ES_DATA_TYPE_INT,
37-
self::INTERNAL_DATA_TYPE_DATE => self::ES_DATA_TYPE_DATE,
38-
];
39-
40-
/**
41-
* Get service field type for elasticsearch 5.
42-
*
43-
* @param string $internalType
44-
* @return string
45-
* @throws \DomainException
46-
*/
47-
public function convert(string $internalType): string
48-
{
49-
if (!isset($this->mapping[$internalType])) {
50-
throw new \DomainException(sprintf('Unsupported internal field type: %s', $internalType));
51-
}
52-
return $this->mapping[$internalType];
53-
}
5417
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Resolver/CompositeResolver.php

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,11 @@
77

88
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Resolver;
99

10-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter;
11-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface;
12-
1310
/**
14-
* Composite resolver for resolving field type.
11+
* @deprecated Handle the Backward Compatibility issue with ES7 and ES8
12+
* @see AC-10652
13+
* phpcs:disable Generic.Files.LineLength.TooLong
1514
*/
16-
class CompositeResolver implements ResolverInterface
15+
class CompositeResolver extends \Magento\Elasticsearch\ElasticAdapter\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Resolver\CompositeResolver
1716
{
18-
/**
19-
* @var ResolverInterface[]
20-
*/
21-
private $items;
22-
23-
/**
24-
* @param ResolverInterface[] $items
25-
*/
26-
public function __construct(array $items)
27-
{
28-
foreach ($items as $item) {
29-
if (!$item instanceof ResolverInterface) {
30-
throw new \InvalidArgumentException(
31-
sprintf('Instance of the field type resolver is expected, got %s instead.', get_class($item))
32-
);
33-
}
34-
}
35-
$this->items = $items;
36-
}
37-
38-
/**
39-
* Get field type.
40-
*
41-
* @param AttributeAdapter $attribute
42-
* @return string
43-
*/
44-
public function getFieldType(AttributeAdapter $attribute): ?string
45-
{
46-
$result = null;
47-
foreach ($this->items as $item) {
48-
$result = $item->getFieldType($attribute);
49-
if (null !== $result) {
50-
break;
51-
}
52-
}
53-
54-
return $result;
55-
}
5617
}

0 commit comments

Comments
 (0)