Skip to content

Commit 5ea8151

Browse files
authored
Merge pull request #3792 from magento-arcticfoxes/2.3.1-qwerty-pr
[2.3.1-qwerty] Sync with 2.3.1-release
2 parents 4efed2d + 298a243 commit 5ea8151

File tree

21 files changed

+87
-408
lines changed

21 files changed

+87
-408
lines changed

app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private function getProductIdsByActions(array $actions)
143143
$productIds = [];
144144

145145
foreach ($actions as $action) {
146-
if (isset($action['product_id']) && is_int($action['product_id'])) {
146+
if (isset($action['product_id'])) {
147147
$productIds[] = $action['product_id'];
148148
}
149149
}

app/code/Magento/Catalog/Test/Unit/Model/Product/ProductFrontendAction/SynchronizerTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ protected function setUp()
8080

8181
public function testFilterProductActions()
8282
{
83+
$typeId = 'recently_compared_product';
8384
$productsData = [
8485
1 => [
8586
'added_at' => 12,
8687
'product_id' => 1,
8788
],
8889
2 => [
8990
'added_at' => 13,
90-
'product_id' => 2,
91+
'product_id' => '2',
9192
],
9293
3 => [
9394
'added_at' => 14,
@@ -126,10 +127,12 @@ public function testFilterProductActions()
126127
$collection->expects($this->once())
127128
->method('addFilterByUserIdentities')
128129
->with(1, 34);
129-
$collection->expects($this->any())
130+
$collection->expects($this->at(1))
130131
->method('addFieldToFilter')
131-
->withConsecutive(['type_id'], ['product_id']);
132-
132+
->with('type_id', $typeId);
133+
$collection->expects($this->at(2))
134+
->method('addFieldToFilter')
135+
->with('product_id', [1, 2]);
133136
$iterator = new \IteratorIterator(new \ArrayIterator([$frontendAction]));
134137
$collection->expects($this->once())
135138
->method('getIterator')

app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function getFields(array $context = []): array
126126
foreach ($groups as $group) {
127127
$groupPriceKey = $this->fieldNameResolver->getFieldName(
128128
$priceAttribute,
129-
array_merge($context, ['customerGroupId' => $group->getId()])
129+
['customerGroupId' => $group->getId(), 'websiteId' => $context['websiteId']]
130130
);
131131
$allAttributes[$groupPriceKey] = [
132132
'type' => $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_FLOAT),

app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Term.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ public function build(
2222
array $queryResult,
2323
DataProviderInterface $dataProvider
2424
) {
25-
$buckets = $queryResult['aggregations'][$bucket->getName()]['buckets'] ?? [];
2625
$values = [];
27-
foreach ($buckets as $resultBucket) {
26+
foreach ($queryResult['aggregations'][$bucket->getName()]['buckets'] as $resultBucket) {
2827
$values[$resultBucket['key']] = [
2928
'value' => $resultBucket['key'],
3029
'count' => $resultBucket['doc_count'],
3130
];
3231
}
33-
3432
return $values;
3533
}
3634
}

app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Elasticsearch\SearchAdapter\Query\Builder;
77

8-
use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool;
9-
use Magento\Framework\App\ObjectManager;
108
use Magento\Framework\Search\Request\Query\BoolExpression;
119
use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface;
1210
use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface;
@@ -28,31 +26,20 @@ class Match implements QueryInterface
2826
private $fieldMapper;
2927

3028
/**
31-
* @deprecated
32-
* @see \Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer
3329
* @var PreprocessorInterface[]
3430
*/
3531
protected $preprocessorContainer;
3632

37-
/**
38-
* @var ValueTransformerPool
39-
*/
40-
private $valueTransformerPool;
41-
4233
/**
4334
* @param FieldMapperInterface $fieldMapper
4435
* @param PreprocessorInterface[] $preprocessorContainer
45-
* @param ValueTransformerPool|null $valueTransformerPool
4636
*/
4737
public function __construct(
4838
FieldMapperInterface $fieldMapper,
49-
array $preprocessorContainer,
50-
ValueTransformerPool $valueTransformerPool = null
39+
array $preprocessorContainer
5140
) {
5241
$this->fieldMapper = $fieldMapper;
5342
$this->preprocessorContainer = $preprocessorContainer;
54-
$this->valueTransformerPool = $valueTransformerPool ?? ObjectManager::getInstance()
55-
->get(ValueTransformerPool::class);
5643
}
5744

5845
/**
@@ -85,6 +72,10 @@ public function build(array $selectQuery, RequestQueryInterface $requestQuery, $
8572
*/
8673
protected function prepareQuery($queryValue, $conditionType)
8774
{
75+
$queryValue = $this->escape($queryValue);
76+
foreach ($this->preprocessorContainer as $preprocessor) {
77+
$queryValue = $preprocessor->process($queryValue);
78+
}
8879
$condition = $conditionType === BoolExpression::QUERY_CONDITION_NOT ?
8980
self::QUERY_CONDITION_MUST_NOT : $conditionType;
9081
return [
@@ -113,34 +104,21 @@ protected function buildQueries(array $matches, array $queryValue)
113104

114105
// Checking for quoted phrase \"phrase test\", trim escaped surrounding quotes if found
115106
$count = 0;
116-
$value = preg_replace('#^"(.*)"$#m', '$1', $queryValue['value'], -1, $count);
107+
$value = preg_replace('#^\\\\"(.*)\\\\"$#m', '$1', $queryValue['value'], -1, $count);
117108
$condition = ($count) ? 'match_phrase' : 'match';
118109

119-
$attributesTypes = $this->fieldMapper->getAllAttributesTypes();
120-
$transformedTypes = [];
121110
foreach ($matches as $match) {
122111
$resolvedField = $this->fieldMapper->getFieldName(
123112
$match['field'],
124113
['type' => FieldMapperInterface::TYPE_QUERY]
125114
);
126-
$valueTransformer = $this->valueTransformerPool->get($attributesTypes[$resolvedField]['type'] ?? 'text');
127-
$valueTransformerHash = \spl_object_hash($valueTransformer);
128-
if (!isset($transformedTypes[$valueTransformerHash])) {
129-
$transformedTypes[$valueTransformerHash] = $valueTransformer->transform($value);
130-
}
131-
$transformedValue = $transformedTypes[$valueTransformerHash];
132-
if (null === $transformedValue) {
133-
//Value is incompatible with this field type.
134-
continue;
135-
}
136-
137115
$conditions[] = [
138116
'condition' => $queryValue['condition'],
139117
'body' => [
140118
$condition => [
141119
$resolvedField => [
142-
'query' => $transformedValue,
143-
'boost' => $match['boost'] ?? 1,
120+
'query' => $value,
121+
'boost' => isset($match['boost']) ? $match['boost'] : 1,
144122
],
145123
],
146124
],
@@ -153,13 +131,16 @@ protected function buildQueries(array $matches, array $queryValue)
153131
/**
154132
* Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
155133
*
156-
* @deprecated
157-
* @see \Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer
134+
* Cut trailing plus or minus sign, and @ symbol, using of which causes InnoDB to report a syntax error.
135+
* https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Fulltext-boolean search docs.
136+
*
158137
* @param string $value
159138
* @return string
160139
*/
161140
protected function escape($value)
162141
{
142+
$value = preg_replace('/@+|[@+-]+$/', '', $value);
143+
163144
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
164145
$replace = '\\\$1';
165146

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/DateTransformer.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/FloatTransformer.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/IntegerTransformer.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/TextTransformer.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformerInterface.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)