Skip to content

Commit 053ced8

Browse files
committed
MC-33297: ES validation fails during install on Cloud
1 parent f34a8be commit 053ced8

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function configure(array $inputOptions)
6363
$configKey = $this->searchConfigMapping[$inputKey];
6464
$this->configWriter->save(self::CATALOG_SEARCH . $configKey, $inputValue);
6565
}
66-
if (!$this->validator->validate($inputOptions[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE])) {
66+
$searchEngine = $inputOptions[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE] ?? null;
67+
if (!$this->validator->validate($searchEngine)) {
6768
throw new InputException(
6869
__(
6970
'Connection to Elasticsearch cannot be established. '

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Search\Setup;
99

10+
use Magento\Config\Model\Config\Backend\Admin\Custom;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1012
use Magento\Framework\Exception\InputException;
1113

1214
/**
@@ -20,10 +22,17 @@ class CompositeInstallConfig implements InstallConfigInterface
2022
private $installConfigList;
2123

2224
/**
25+
* @var ScopeConfigInterface
26+
*/
27+
private $scopeConfig;
28+
29+
/**
30+
* @param ScopeConfigInterface $scopeConfig
2331
* @param InstallConfigInterface[] $installConfigList
2432
*/
25-
public function __construct(array $installConfigList)
33+
public function __construct(ScopeConfigInterface $scopeConfig, array $installConfigList)
2634
{
35+
$this->scopeConfig = $scopeConfig;
2736
$this->installConfigList = $installConfigList;
2837
}
2938

@@ -32,7 +41,11 @@ public function __construct(array $installConfigList)
3241
*/
3342
public function configure(array $inputOptions)
3443
{
35-
$searchEngine = $inputOptions['search-engine'];
44+
if (isset($inputOptions['search-engine'])) {
45+
$searchEngine = $inputOptions['search-engine'];
46+
} else {
47+
$searchEngine = $this->scopeConfig->getValue(Custom::XML_PATH_CATALOG_SEARCH_ENGINE);
48+
}
3649

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

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 & 14 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

@@ -51,28 +50,25 @@ public function getOptionsList(): array
5150
SelectConfigOption::FRONTEND_WIZARD_SELECT,
5251
array_keys($this->getAvailableSearchEngineList()),
5352
'',
54-
'Search engine. Values: ' . implode(', ', array_keys($this->getAvailableSearchEngineList())),
55-
self::DEFAULT_SEARCH_ENGINE
53+
'Search engine. Values: ' . implode(', ', array_keys($this->getAvailableSearchEngineList()))
5654
),
5755
new TextConfigOption(
5856
self::INPUT_KEY_ELASTICSEARCH_HOST,
5957
TextConfigOption::FRONTEND_WIZARD_TEXT,
6058
'',
61-
'Elasticsearch server host.',
62-
self::DEFAULT_ELASTICSEARCH_HOST
59+
'Elasticsearch server host.'
6360
),
6461
new TextConfigOption(
6562
self::INPUT_KEY_ELASTICSEARCH_PORT,
6663
TextConfigOption::FRONTEND_WIZARD_TEXT,
6764
'',
68-
'Elasticsearch server port.',
69-
self::DEFAULT_ELASTICSEARCH_PORT
65+
'Elasticsearch server port.'
7066
),
71-
new FlagConfigOption(
67+
new TextConfigOption(
7268
self::INPUT_KEY_ELASTICSEARCH_ENABLE_AUTH,
69+
TextConfigOption::FRONTEND_WIZARD_TEXT,
7370
'',
74-
'Enable Elasticsearch HTTP authentication.',
75-
null
71+
'Set to 1 to enable authentication. (default is 0, disabled)'
7672
),
7773
new TextConfigOption(
7874
self::INPUT_KEY_ELASTICSEARCH_USERNAME,
@@ -90,15 +86,13 @@ public function getOptionsList(): array
9086
self::INPUT_KEY_ELASTICSEARCH_INDEX_PREFIX,
9187
TextConfigOption::FRONTEND_WIZARD_TEXT,
9288
'',
93-
'Elasticsearch index prefix.',
94-
self::DEFAULT_ELASTICSEARCH_INDEX_PREFIX
89+
'Elasticsearch index prefix.'
9590
),
9691
new TextConfigOption(
9792
self::INPUT_KEY_ELASTICSEARCH_TIMEOUT,
9893
TextConfigOption::FRONTEND_WIZARD_TEXT,
9994
'',
100-
'Elasticsearch server timeout.',
101-
self::DEFAULT_ELASTICSEARCH_TIMEOUT
95+
'Elasticsearch server timeout.'
10296
)
10397
];
10498
}

0 commit comments

Comments
 (0)