Skip to content

Commit fa563d4

Browse files
committed
MC-19282: Add Elasticsearch configuration parameters to web setup
1 parent 9f594ec commit fa563d4

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

setup/config/states.install.config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
//phpcs:ignore
78
$base = basename($_SERVER['SCRIPT_FILENAME']);
89

910
return [
@@ -101,6 +102,7 @@
101102
'header' => 'Step 5: Configure Catalog Search',
102103
'controller' => 'configureCatalogSearchController',
103104
'nav' => true,
105+
'validate' => true,
104106
'order' => 6,
105107
'type' => 'install'
106108
],

setup/pub/magento/setup/configure-catalog-search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ angular.module('configure-catalog-search', ['ngStorage', 'ngSanitize'])
7676
'An unknown error occurred. Please check configuration and try again.';
7777
$scope.checking = false;
7878
});
79-
}
79+
};
8080
}]);

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,46 @@ private function convertAdminUserForm(array $source)
133133
private function convertSearchConfigForm(array $source): array
134134
{
135135
$result = [];
136+
if (!isset($source['search'])) {
137+
return $result;
138+
}
136139
$result[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE] =
137-
isset($source['search']['engine']) ? $source['search']['engine'] : '';
140+
$this->getValueFromArray($source['search'], 'engine', '');
138141

139142
$esConfig = $source['search']['elasticsearch'];
140143
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_HOST] =
141-
isset($esConfig['hostname']) ? $esConfig['hostname'] : '';
144+
$this->getValueFromArray($esConfig, 'hostname', '');
142145
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_PORT] =
143-
isset($esConfig['port']) ? $esConfig['port'] : '';
146+
$this->getValueFromArray($esConfig, 'port', '');
144147
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_INDEX_PREFIX] =
145-
isset($esConfig['indexPrefix']) ? $esConfig['indexPrefix'] : '';
148+
$this->getValueFromArray($esConfig, 'indexPrefix', '');
146149
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_TIMEOUT] =
147-
isset($esConfig['timeout']) ? $esConfig['timeout'] : '';
150+
$this->getValueFromArray($esConfig, 'timeout', '');
151+
148152
if (isset($esConfig['enableAuth']) && true === $esConfig['enableAuth']) {
149153
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_ENABLE_AUTH] = $esConfig['enableAuth'];
150154
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_USERNAME] =
151-
isset($esConfig['username']) ? $esConfig['username'] : '';
155+
$this->getValueFromArray($esConfig, 'username', '');
152156
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_PASSWORD] =
153-
isset($esConfig['password']) ? $esConfig['password'] : '';
157+
$this->getValueFromArray($esConfig, 'password', '');
154158
} else {
155159
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_ENABLE_AUTH] =
156-
isset($esConfig['enableAuth']) ? $esConfig['enableAuth'] : false;
160+
$this->getValueFromArray($esConfig, 'enableAuth', false);
157161
}
158162

159163
return $result;
160164
}
165+
166+
/**
167+
* Get value from array by key, or return default
168+
*
169+
* @param array $array
170+
* @param string $key
171+
* @param mixed $defaultValue
172+
* @return mixed
173+
*/
174+
private function getValueFromArray(array $array, string $key, $defaultValue = null)
175+
{
176+
return isset($array[$key]) ? $array[$key] : $defaultValue;
177+
}
161178
}

setup/view/layout/layout.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
// @codingStandardsIgnoreFile
8+
69
?>
710
<?= $this->doctype() ?>
811
<!--[if !IE]><!-->

setup/view/magento/setup/configure-catalog-search.phtml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@
8383
tooltip-trigger="focus"
8484
tooltip-append-to-body="true"
8585
type="text"
86+
ng-class="{'invalid' : searchConfig.elasticsearchHost.$invalid && searchConfig.submitted}"
8687
name="elasticsearchHost"
8788
ng-model="search.config.elasticsearch.hostname"
8889
required
8990
>
91+
<div class="error-container">
92+
<span ng-show="searchConfig.elasticsearchHost.$invalid">
93+
Hostname is required.
94+
</span>
95+
</div>
9096
</div>
9197
</div>
9298
<div class="row form-row">
@@ -104,10 +110,17 @@
104110
tooltip-trigger="focus"
105111
tooltip-append-to-body="true"
106112
type="text"
113+
ng-pattern="/^[0-9]+$/"
114+
ng-class="{'invalid' : searchConfig.elasticsearchPort.$invalid && searchConfig.submitted}"
107115
name="elasticsearchPort"
108116
ng-model="search.config.elasticsearch.port"
109117
required
110118
>
119+
<div class="error-container">
120+
<span ng-show="searchConfig.elasticsearchPort.$invalid">
121+
Port is required and must be a numeric value.
122+
</span>
123+
</div>
111124
</div>
112125
</div>
113126
<div class="row form-row">
@@ -187,7 +200,6 @@
187200
type="text"
188201
name="elasticsearchIndexPrefix"
189202
ng-model="search.config.elasticsearch.indexPrefix"
190-
required
191203
>
192204
</div>
193205
</div>
@@ -206,10 +218,17 @@
206218
tooltip-trigger="focus"
207219
tooltip-append-to-body="true"
208220
type="text"
221+
ng-pattern="/^[0-9]+$/"
222+
ng-class="{'invalid' : searchConfig.elasticsearchTimeout.$invalid && searchConfig.submitted}"
209223
name="elasticsearchTimeout"
210224
ng-model="search.config.elasticsearch.timeout"
211225
required
212226
>
227+
<div class="error-container">
228+
<span ng-show="searchConfig.elasticsearchTimeout.$invalid">
229+
Please enter a number greater than 0.
230+
</span>
231+
</div>
213232
</div>
214233
</div>
215234
<div class="row form-row">

0 commit comments

Comments
 (0)