Skip to content

Commit 3aa6cd9

Browse files
authored
Merge branch '2.4-develop' into ui/admin/roles-tree
2 parents 7e01a64 + ffeb0a0 commit 3aa6cd9

File tree

22 files changed

+609
-141
lines changed

22 files changed

+609
-141
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdvancedSearch\Helper;
9+
10+
use Magento\Framework\App\Helper\Context;
11+
use Magento\Framework\Search\EngineResolverInterface;
12+
use Magento\Framework\App\Helper\AbstractHelper;
13+
use OpenSearch\Client;
14+
15+
class Data extends AbstractHelper
16+
{
17+
18+
public const OPENSEARCH = 'opensearch';
19+
public const MAJOR_VERSION = '2';
20+
21+
/**
22+
* @var EngineResolverInterface
23+
*/
24+
public $engineResolver;
25+
26+
/**
27+
* @param Context $context
28+
* @param EngineResolverInterface $engineResolver
29+
*/
30+
public function __construct(
31+
Context $context,
32+
EngineResolverInterface $engineResolver
33+
) {
34+
parent::__construct($context);
35+
$this->engineResolver = $engineResolver;
36+
}
37+
38+
/**
39+
* Check if opensearch v2.x
40+
*
41+
* @return bool
42+
*/
43+
public function isClientOpenSearchV2(): bool
44+
{
45+
$searchEngine = $this->engineResolver->getCurrentSearchEngine();
46+
if (stripos($searchEngine, self::OPENSEARCH) !== false) {
47+
if (substr(Client::VERSION, 0, 1) == self::MAJOR_VERSION) {
48+
return true;
49+
}
50+
}
51+
return false;
52+
}
53+
}

app/code/Magento/AdvancedSearch/Model/Client/ClientFactory.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
namespace Magento\AdvancedSearch\Model\Client;
77

88
use Magento\Framework\ObjectManagerInterface;
9+
use Magento\AdvancedSearch\Helper\Data;
910

1011
class ClientFactory implements ClientFactoryInterface
1112
{
1213
/**
13-
* Object manager
14+
* Object var
1415
*
1516
* @var ObjectManagerInterface
1617
*/
@@ -21,14 +22,32 @@ class ClientFactory implements ClientFactoryInterface
2122
*/
2223
private $clientClass;
2324

25+
/**
26+
* @var string
27+
*/
28+
private $openSearch;
29+
30+
/**
31+
* @var Data
32+
*/
33+
protected $helper;
34+
2435
/**
2536
* @param ObjectManagerInterface $objectManager
2637
* @param string $clientClass
38+
* @param Data $helper
39+
* @param string|null $openSearch
2740
*/
28-
public function __construct(ObjectManagerInterface $objectManager, $clientClass)
29-
{
41+
public function __construct(
42+
ObjectManagerInterface $objectManager,
43+
$clientClass,
44+
Data $helper,
45+
$openSearch = null
46+
) {
3047
$this->objectManager = $objectManager;
3148
$this->clientClass = $clientClass;
49+
$this->openSearch = $openSearch;
50+
$this->helper = $helper;
3251
}
3352

3453
/**
@@ -39,8 +58,13 @@ public function __construct(ObjectManagerInterface $objectManager, $clientClass)
3958
*/
4059
public function create(array $options = [])
4160
{
61+
$class = $this->clientClass;
62+
if ($this->helper->isClientOpenSearchV2()) {
63+
$class = $this->openSearch;
64+
}
65+
4266
return $this->objectManager->create(
43-
$this->clientClass,
67+
$class,
4468
['options' => $options]
4569
);
4670
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdvancedSearch\Test\Unit\Helper;
9+
10+
use Magento\AdvancedSearch\Helper\Data;
11+
use Magento\Framework\App\Helper\Context;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
use Magento\Framework\Search\EngineResolverInterface;
16+
17+
/**
18+
* @covers \Magento\AdvancedSearch\Helper\Data
19+
*/
20+
class DataTest extends TestCase
21+
{
22+
23+
/**
24+
* @var Data
25+
*/
26+
private $helper;
27+
28+
/**
29+
* @var Context|MockObject
30+
*/
31+
private $contextMock;
32+
33+
/**
34+
* @var EngineResolverInterface|MockObject
35+
*/
36+
private $engineResolverMock;
37+
38+
/**
39+
* @var ObjectManagerHelper
40+
*/
41+
private $objectManager;
42+
43+
/**
44+
* @return void
45+
*/
46+
protected function setUp(): void
47+
{
48+
$this->contextMock = $this->getMockBuilder(Context::class)
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$this->engineResolverMock = $this->getMockForAbstractClass(EngineResolverInterface::class);
53+
54+
$this->engineResolverMock->expects($this->any())
55+
->method('getCurrentSearchEngine')
56+
->willReturn('');
57+
58+
$this->objectManager = new ObjectManagerHelper($this);
59+
$this->helper = $this->objectManager->getObject(
60+
Data::class,
61+
[
62+
'context' => $this->contextMock,
63+
'engineResolver' => $this->engineResolverMock
64+
]
65+
);
66+
}
67+
68+
public function testIsClientOpenSearchV2()
69+
{
70+
$this->assertIsBool($this->helper->isClientOpenSearchV2());
71+
}
72+
}

app/code/Magento/Checkout/Test/Mftf/ActionGroup/AssertMiniCartEmptyActionGroup.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
<wait stepKey="waitForMinicartAjaxCallToComplete" time="15"/>
1717
<dontSeeElement selector="{{StorefrontMinicartSection.productCount}}" stepKey="dontSeeMinicartProductCount"/>
1818
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="expandMinicart"/>
19-
<see selector="{{StorefrontMinicartSection.minicartContent}}" userInput="You have no items in your shopping cart." stepKey="seeEmptyCartMessage"/>
19+
<see selector="{{StorefrontMinicartSection.messageEmptyCart}}" userInput="You have no items in your shopping cart." stepKey="seeEmptyCartMessage"/>
2020
</actionGroup>
2121
</actionGroups>

app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
use Magento\Framework\Exception\LocalizedException;
2020
use Magento\Framework\Stdlib\ArrayManager;
2121
use Psr\Log\LoggerInterface;
22+
use Magento\AdvancedSearch\Helper\Data;
2223

2324
/**
2425
* Elasticsearch adapter
26+
* @SuppressWarnings(PHPMD.TooManyFields)
2527
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
2729
class Elasticsearch
@@ -110,6 +112,11 @@ class Elasticsearch
110112
*/
111113
private $arrayManager;
112114

115+
/**
116+
* @var Data
117+
*/
118+
protected $helper;
119+
113120
/**
114121
* @var array
115122
*/
@@ -125,6 +132,7 @@ class Elasticsearch
125132
* @param LoggerInterface $logger
126133
* @param Index\IndexNameResolver $indexNameResolver
127134
* @param BatchDataMapperInterface $batchDocumentDataMapper
135+
* @param Data $helper
128136
* @param array $options
129137
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
130138
* @param StaticField|null $staticFieldProvider
@@ -141,6 +149,7 @@ public function __construct(
141149
LoggerInterface $logger,
142150
IndexNameResolver $indexNameResolver,
143151
BatchDataMapperInterface $batchDocumentDataMapper,
152+
Data $helper,
144153
$options = [],
145154
ProductAttributeRepositoryInterface $productAttributeRepository = null,
146155
StaticField $staticFieldProvider = null,
@@ -154,6 +163,7 @@ public function __construct(
154163
$this->logger = $logger;
155164
$this->indexNameResolver = $indexNameResolver;
156165
$this->batchDocumentDataMapper = $batchDocumentDataMapper;
166+
$this->helper = $helper;
157167
$this->productAttributeRepository = $productAttributeRepository ?:
158168
ObjectManager::getInstance()->get(ProductAttributeRepositoryInterface::class);
159169
$this->staticFieldProvider = $staticFieldProvider ?:
@@ -329,18 +339,30 @@ protected function getDocsArrayInBulkIndexFormat(
329339
];
330340

331341
foreach ($documents as $id => $document) {
332-
$bulkArray['body'][] = [
333-
$action => [
334-
'_id' => $id,
335-
'_type' => $this->clientConfig->getEntityType(),
336-
'_index' => $indexName
337-
]
338-
];
342+
if ($this->helper->isClientOpenSearchV2()) {
343+
$bulkArray['body'][] = [
344+
$action => [
345+
'_id' => $id,
346+
'_index' => $indexName
347+
]
348+
];
349+
} else {
350+
$bulkArray['body'][] = [
351+
$action => [
352+
'_id' => $id,
353+
'_type' => $this->clientConfig->getEntityType(),
354+
'_index' => $indexName
355+
]
356+
];
357+
}
339358
if ($action == self::BULK_ACTION_INDEX) {
340359
$bulkArray['body'][] = $document;
341360
}
342361
}
343362

363+
if ($this->helper->isClientOpenSearchV2()) {
364+
unset($bulkArray['type']);
365+
}
344366
return $bulkArray;
345367
}
346368

app/code/Magento/Elasticsearch7/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"php": "~8.1.0||~8.2.0",
66
"magento/framework": "*",
77
"magento/module-elasticsearch": "*",
8-
"elasticsearch/elasticsearch": "~7.17.0",
8+
"elasticsearch/elasticsearch": "^7.17",
99
"magento/module-advanced-search": "*",
1010
"magento/module-catalog-search": "*",
1111
"magento/module-search": "*"

app/code/Magento/GraphQl/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"magento/module-webapi": "*",
1010
"magento/module-new-relic-reporting": "*",
1111
"magento/module-authorization": "*",
12-
"webonyx/graphql-php": "~14.11.5"
12+
"webonyx/graphql-php": "^14.11"
1313
},
1414
"suggest": {
1515
"magento/module-graph-ql-cache": "*"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\OpenSearch\Model;
9+
10+
/**
11+
* The purpose of this class is adding the support for opensearch version 2
12+
*/
13+
14+
class OpenSearch extends SearchClient
15+
{
16+
17+
/**
18+
* Add mapping to OpenSearch index
19+
*
20+
* @param array $fields
21+
* @param string $index
22+
* @param string $entityType
23+
* @return void
24+
*/
25+
public function addFieldsMapping(array $fields, string $index, string $entityType)
26+
{
27+
$params = [
28+
'index' => $index,
29+
'body' => [
30+
'properties' => [],
31+
'dynamic_templates' => $this->dynamicTemplatesProvider->getTemplates(),
32+
],
33+
];
34+
35+
foreach ($this->applyFieldsMappingPreprocessors($fields) as $field => $fieldInfo) {
36+
$params['body']['properties'][$field] = $fieldInfo;
37+
}
38+
39+
$this->getOpenSearchClient()->indices()->putMapping($params);
40+
}
41+
42+
/**
43+
* Execute search by $query
44+
*
45+
* @param array $query
46+
* @return array
47+
*/
48+
public function query(array $query): array
49+
{
50+
unset($query['type']);
51+
return $this->getOpenSearchClient()->search($query);
52+
}
53+
}

app/code/Magento/OpenSearch/Model/SearchClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SearchClient implements ClientInterface
4242
/**
4343
* @var DynamicTemplatesProvider|null
4444
*/
45-
private $dynamicTemplatesProvider;
45+
public $dynamicTemplatesProvider;
4646

4747
/**
4848
* Initialize Client
@@ -93,7 +93,7 @@ public function suggest(array $query): array
9393
*
9494
* @return Client
9595
*/
96-
private function getOpenSearchClient(): Client
96+
public function getOpenSearchClient(): Client
9797
{
9898
$pid = getmypid();
9999
if (!isset($this->client[$pid])) {
@@ -371,7 +371,7 @@ public function deleteMapping(string $index, string $entityType)
371371
* @param array $properties
372372
* @return array
373373
*/
374-
private function applyFieldsMappingPreprocessors(array $properties): array
374+
public function applyFieldsMappingPreprocessors(array $properties): array
375375
{
376376
foreach ($this->fieldsMappingPreprocessors as $preprocessor) {
377377
$properties = $preprocessor->process($properties);

0 commit comments

Comments
 (0)