Skip to content

Commit 67a21cf

Browse files
committed
Merge remote-tracking branch 'origin/MC-33297-es-cloud' into MC-33394-pr-delivery
2 parents 8a1fe92 + c1fd526 commit 67a21cf

File tree

10 files changed

+84
-63
lines changed

10 files changed

+84
-63
lines changed

app/code/Magento/Elasticsearch/Setup/ConnectionValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public function __construct(ClientResolver $clientResolver)
3030
/**
3131
* Checks Elasticsearch Connection
3232
*
33-
* @param string $searchEngine
33+
* @param string|null $searchEngine if empty, uses the currently configured engine
3434
* @return bool true if the connection succeeded, false otherwise
3535
*/
36-
public function validate(string $searchEngine): bool
36+
public function validate(string $searchEngine = null): bool
3737
{
3838
try {
3939
$client = $this->clientResolver->create($searchEngine);

app/code/Magento/Elasticsearch/Setup/InstallConfig.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Elasticsearch\Setup;
99

10+
use Magento\Framework\App\Config\ReinitableConfigInterface;
1011
use Magento\Framework\App\Config\Storage\WriterInterface;
1112
use Magento\Framework\Exception\InputException;
1213
use Magento\Setup\Model\SearchConfigOptionsList;
@@ -36,18 +37,26 @@ class InstallConfig implements InstallConfigInterface
3637
*/
3738
private $configWriter;
3839

40+
/**
41+
* @var ReinitableConfigInterface
42+
*/
43+
private $reinitableConfig;
44+
3945
/**
4046
* @param WriterInterface $configWriter
4147
* @param ConnectionValidator $validator
48+
* @param ReinitableConfigInterface $reinitableConfig
4249
* @param array $searchConfigMapping
4350
*/
4451
public function __construct(
4552
WriterInterface $configWriter,
4653
ConnectionValidator $validator,
54+
ReinitableConfigInterface $reinitableConfig,
4755
array $searchConfigMapping = []
4856
) {
4957
$this->configWriter = $configWriter;
5058
$this->validator = $validator;
59+
$this->reinitableConfig = $reinitableConfig;
5160
$this->searchConfigMapping = array_merge($this->searchConfigMapping, $searchConfigMapping);
5261
}
5362

@@ -63,7 +72,9 @@ public function configure(array $inputOptions)
6372
$configKey = $this->searchConfigMapping[$inputKey];
6473
$this->configWriter->save(self::CATALOG_SEARCH . $configKey, $inputValue);
6574
}
66-
if (!$this->validator->validate($inputOptions[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE])) {
75+
$this->reinitableConfig->reinit();
76+
$searchEngine = $inputOptions[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE] ?? null;
77+
if (!$this->validator->validate($searchEngine)) {
6778
throw new InputException(
6879
__(
6980
'Connection to Elasticsearch cannot be established. '

app/code/Magento/Elasticsearch/Test/Unit/Setup/InstallConfigTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,11 @@ public function testConfigureValidateFail()
112112

113113
$this->installConfig->configure($inputOptions);
114114
}
115+
116+
public function testConfigureWithEmptyInput()
117+
{
118+
$this->configWriterMock->expects($this->never())->method('save');
119+
$this->validatorMock->expects($this->once())->method('validate')->with(null)->willReturn(true);
120+
$this->installConfig->configure([]);
121+
}
115122
}

app/code/Magento/Search/Setup/CompositeInstallConfig.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Search\Setup;
99

1010
use Magento\Framework\Exception\InputException;
11+
use Magento\Framework\Search\EngineResolverInterface;
1112

1213
/**
1314
* Composite object uses the proper InstallConfigInterface implementation for the engine being configured
@@ -20,10 +21,19 @@ class CompositeInstallConfig implements InstallConfigInterface
2021
private $installConfigList;
2122

2223
/**
24+
* @var EngineResolverInterface
25+
*/
26+
private $engineResolver;
27+
28+
/**
29+
* @param EngineResolverInterface $engineResolver
2330
* @param InstallConfigInterface[] $installConfigList
2431
*/
25-
public function __construct(array $installConfigList)
26-
{
32+
public function __construct(
33+
EngineResolverInterface $engineResolver,
34+
array $installConfigList
35+
) {
36+
$this->engineResolver = $engineResolver;
2737
$this->installConfigList = $installConfigList;
2838
}
2939

@@ -32,7 +42,11 @@ public function __construct(array $installConfigList)
3242
*/
3343
public function configure(array $inputOptions)
3444
{
35-
$searchEngine = $inputOptions['search-engine'];
45+
if (isset($inputOptions['search-engine'])) {
46+
$searchEngine = $inputOptions['search-engine'];
47+
} else {
48+
$searchEngine = $this->engineResolver->getCurrentSearchEngine();
49+
}
3650

3751
if (!isset($this->installConfigList[$searchEngine])) {
3852
throw new InputException(__('Unable to configure search engine: %1', $searchEngine));

setup/src/Magento/Setup/Controller/ConfigureCatalogSearch.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ class ConfigureCatalogSearch extends AbstractActionController
2222
*/
2323
private $searchConfigOptionsList;
2424

25+
/**
26+
* Default values to prefill form
27+
*
28+
* @var array
29+
*/
30+
private $prefillConfigValues = [
31+
'engine' => 'elasticsearch7',
32+
'elasticsearch' => [
33+
'hostname' => 'localhost',
34+
'port' => '9200',
35+
'timeout' => '15',
36+
'indexPrefix' => 'magento2',
37+
'enableAuth' => false
38+
]
39+
];
40+
2541
/**
2642
* @param SearchConfigOptionsList $searchConfigOptionsList
2743
*/
@@ -51,17 +67,6 @@ public function indexAction(): ViewModel
5167
*/
5268
public function defaultParametersAction(): JsonModel
5369
{
54-
$defaults = [
55-
'engine' => SearchConfigOptionsList::DEFAULT_SEARCH_ENGINE,
56-
'elasticsearch' => [
57-
'hostname' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_HOST,
58-
'port' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_PORT,
59-
'timeout' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_TIMEOUT,
60-
'indexPrefix' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_INDEX_PREFIX,
61-
'enableAuth' => false
62-
]
63-
];
64-
65-
return new JsonModel($defaults);
70+
return new JsonModel($this->prefillConfigValues);
6671
}
6772
}

setup/src/Magento/Setup/Model/SearchConfig.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ public function saveConfiguration(array $inputOptions)
5050
$searchConfigOptions = $this->extractSearchOptions($inputOptions);
5151
if (!empty($searchConfigOptions[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE])) {
5252
$this->validateSearchEngineSelection($searchConfigOptions);
53-
54-
try {
55-
$this->installConfig->configure($searchConfigOptions);
56-
} catch (InputException $e) {
57-
throw new SetupException($e->getMessage());
58-
}
53+
}
54+
try {
55+
$this->installConfig->configure($searchConfigOptions);
56+
} catch (InputException $e) {
57+
throw new SetupException($e->getMessage());
5958
}
6059
}
6160

setup/src/Magento/Setup/Model/SearchConfigOptionsList.php

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\Setup\Model;
99

1010
use Magento\Framework\Setup\Option\AbstractConfigOption;
11-
use Magento\Framework\Setup\Option\FlagConfigOption;
1211
use Magento\Framework\Setup\Option\SelectConfigOption;
1312
use Magento\Framework\Setup\Option\TextConfigOption;
1413

@@ -29,15 +28,6 @@ class SearchConfigOptionsList
2928
const INPUT_KEY_ELASTICSEARCH_INDEX_PREFIX = 'elasticsearch-index-prefix';
3029
const INPUT_KEY_ELASTICSEARCH_TIMEOUT = 'elasticsearch-timeout';
3130

32-
/**
33-
* Default values
34-
*/
35-
const DEFAULT_SEARCH_ENGINE = 'elasticsearch7';
36-
const DEFAULT_ELASTICSEARCH_HOST = 'localhost';
37-
const DEFAULT_ELASTICSEARCH_PORT = '9200';
38-
const DEFAULT_ELASTICSEARCH_INDEX_PREFIX = 'magento2';
39-
const DEFAULT_ELASTICSEARCH_TIMEOUT = 15;
40-
4131
/**
4232
* Get options list for search engine configuration
4333
*
@@ -51,28 +41,25 @@ public function getOptionsList(): array
5141
SelectConfigOption::FRONTEND_WIZARD_SELECT,
5242
array_keys($this->getAvailableSearchEngineList()),
5343
'',
54-
'Search engine. Values: ' . implode(', ', array_keys($this->getAvailableSearchEngineList())),
55-
self::DEFAULT_SEARCH_ENGINE
44+
'Search engine. Values: ' . implode(', ', array_keys($this->getAvailableSearchEngineList()))
5645
),
5746
new TextConfigOption(
5847
self::INPUT_KEY_ELASTICSEARCH_HOST,
5948
TextConfigOption::FRONTEND_WIZARD_TEXT,
6049
'',
61-
'Elasticsearch server host.',
62-
self::DEFAULT_ELASTICSEARCH_HOST
50+
'Elasticsearch server host.'
6351
),
6452
new TextConfigOption(
6553
self::INPUT_KEY_ELASTICSEARCH_PORT,
6654
TextConfigOption::FRONTEND_WIZARD_TEXT,
6755
'',
68-
'Elasticsearch server port.',
69-
self::DEFAULT_ELASTICSEARCH_PORT
56+
'Elasticsearch server port.'
7057
),
71-
new FlagConfigOption(
58+
new TextConfigOption(
7259
self::INPUT_KEY_ELASTICSEARCH_ENABLE_AUTH,
60+
TextConfigOption::FRONTEND_WIZARD_TEXT,
7361
'',
74-
'Enable Elasticsearch HTTP authentication.',
75-
null
62+
'Set to 1 to enable authentication. (default is 0, disabled)'
7663
),
7764
new TextConfigOption(
7865
self::INPUT_KEY_ELASTICSEARCH_USERNAME,
@@ -90,15 +77,13 @@ public function getOptionsList(): array
9077
self::INPUT_KEY_ELASTICSEARCH_INDEX_PREFIX,
9178
TextConfigOption::FRONTEND_WIZARD_TEXT,
9279
'',
93-
'Elasticsearch index prefix.',
94-
self::DEFAULT_ELASTICSEARCH_INDEX_PREFIX
80+
'Elasticsearch index prefix.'
9581
),
9682
new TextConfigOption(
9783
self::INPUT_KEY_ELASTICSEARCH_TIMEOUT,
9884
TextConfigOption::FRONTEND_WIZARD_TEXT,
9985
'',
100-
'Elasticsearch server timeout.',
101-
self::DEFAULT_ELASTICSEARCH_TIMEOUT
86+
'Elasticsearch server timeout.'
10287
)
10388
];
10489
}

setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Config\ConfigOptionsListConstants as SetupConfigOptionsList;
1919
use Magento\Setup\Model\StoreConfigurationDataMapper;
2020
use Magento\Setup\Console\Command\AdminUserCreateCommand;
21+
use PHPUnit\Framework\MockObject\MockObject;
2122

2223
/**
2324
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -30,42 +31,42 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
3031
private $input;
3132

3233
/**
33-
* @var \PHPUnit_Framework_MockObject_MockObject|InstallCommand
34+
* @var MockObject|InstallCommand
3435
*/
3536
private $command;
3637

3738
/**
38-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\InstallerFactory
39+
* @var MockObject|\Magento\Setup\Model\InstallerFactory
3940
*/
4041
private $installerFactory;
4142

4243
/**
43-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Installer
44+
* @var MockObject|\Magento\Setup\Model\Installer
4445
*/
4546
private $installer;
4647

4748
/**
48-
* @var Application|\PHPUnit_Framework_MockObject_MockObject
49+
* @var Application|MockObject
4950
*/
5051
private $applicationMock;
5152

5253
/**
53-
* @var HelperSet|\PHPUnit_Framework_MockObject_MockObject
54+
* @var HelperSet|MockObject
5455
*/
5556
private $helperSetMock;
5657

5758
/**
58-
* @var InputDefinition|\PHPUnit_Framework_MockObject_MockObject
59+
* @var InputDefinition|MockObject
5960
*/
6061
private $definitionMock;
6162

6263
/**
63-
* @var ConfigImportCommand|\PHPUnit_Framework_MockObject_MockObject
64+
* @var ConfigImportCommand|MockObject
6465
*/
6566
private $configImportMock;
6667

6768
/**
68-
* @var AdminUserCreateCommand|\PHPUnit_Framework_MockObject_MockObject
69+
* @var AdminUserCreateCommand|MockObject
6970
*/
7071
private $adminUserMock;
7172

setup/src/Magento/Setup/Test/Unit/Controller/ConfigureCatalogSearchTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace Magento\Setup\Test\Unit\Controller;
99

1010
use Laminas\View\Model\JsonModel;
11+
use Laminas\View\Model\ViewModel;
1112
use Magento\Setup\Controller\ConfigureCatalogSearch;
1213
use Magento\Setup\Model\SearchConfigOptionsList;
1314
use PHPUnit\Framework\TestCase;
14-
use Zend\View\Model\ViewModel;
1515

1616
class ConfigureCatalogSearchTest extends TestCase
1717
{
@@ -50,12 +50,12 @@ public function testDefaultParametersAction()
5050
$this->assertInstanceOf(JsonModel::class, $jsonModel);
5151

5252
$expectedDefaultParameters = [
53-
'engine' => SearchConfigOptionsList::DEFAULT_SEARCH_ENGINE,
53+
'engine' => 'elasticsearch7',
5454
'elasticsearch' => [
55-
'hostname' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_HOST,
56-
'port' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_PORT,
57-
'timeout' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_TIMEOUT,
58-
'indexPrefix' => SearchConfigOptionsList::DEFAULT_ELASTICSEARCH_INDEX_PREFIX,
55+
'hostname' => 'localhost',
56+
'port' => '9200',
57+
'timeout' => '15',
58+
'indexPrefix' => 'magento2',
5959
'enableAuth' => false
6060
]
6161
];

setup/src/Magento/Setup/Test/Unit/Model/SearchConfigOptionsListTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\Setup\Test\Unit\Model;
99

10-
use Magento\Framework\Setup\Option\FlagConfigOption;
1110
use Magento\Framework\Setup\Option\SelectConfigOption;
1211
use Magento\Framework\Setup\Option\TextConfigOption;
1312
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -49,7 +48,7 @@ public function testGetOptionsList()
4948
$this->assertEquals('elasticsearch-port', $optionsList[2]->getName());
5049

5150
$this->assertArrayHasKey(3, $optionsList);
52-
$this->assertInstanceOf(FlagConfigOption::class, $optionsList[3]);
51+
$this->assertInstanceOf(TextConfigOption::class, $optionsList[3]);
5352
$this->assertEquals('elasticsearch-enable-auth', $optionsList[3]->getName());
5453

5554
$this->assertArrayHasKey(4, $optionsList);

0 commit comments

Comments
 (0)