Skip to content

Commit e600d64

Browse files
committed
MC-19282: Add Elasticsearch configuration parameters to web setup
1 parent 7167c70 commit e600d64

File tree

12 files changed

+567
-8
lines changed

12 files changed

+567
-8
lines changed

setup/config/states.install.config.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,38 @@
9393
'order' => 5,
9494
'type' => 'install'
9595
],
96+
[
97+
'id' => 'root.configure-catalog-search',
98+
'url' => 'configure-catalog-search',
99+
'templateUrl' => "{$base}/configure-catalog-search",
100+
'title' => "Configure \n Search",
101+
'header' => 'Step 5: Configure Catalog Search',
102+
'controller' => 'configureCatalogSearchController',
103+
'nav' => true,
104+
'order' => 6,
105+
'type' => 'install'
106+
],
96107
[
97108
'id' => 'root.create-admin-account',
98109
'url' => 'create-admin-account',
99110
'templateUrl' => "{$base}/create-admin-account",
100111
'title' => "Create \n Admin Account",
101-
'header' => 'Step 5: Create Admin Account',
112+
'header' => 'Step 6: Create Admin Account',
102113
'controller' => 'createAdminAccountController',
103114
'nav' => true,
104115
'validate' => true,
105-
'order' => 6,
116+
'order' => 7,
106117
'type' => 'install'
107118
],
108119
[
109120
'id' => 'root.install',
110121
'url' => 'install',
111122
'templateUrl' => "{$base}/install",
112123
'title' => 'Install',
113-
'header' => 'Step 6: Install',
124+
'header' => 'Step 7: Install',
114125
'controller' => 'installController',
115126
'nav' => true,
116-
'order' => 7,
127+
'order' => 8,
117128
'type' => 'install'
118129
],
119130
[
@@ -123,7 +134,7 @@
123134
'title' => 'Success',
124135
'controller' => 'successController',
125136
'main' => true,
126-
'order' => 8,
137+
'order' => 9,
127138
'type' => 'install'
128139
],
129140
],

setup/pub/magento/setup/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var app = angular.module(
1515
'add-database',
1616
'web-configuration',
1717
'customize-your-store',
18+
'configure-catalog-search',
1819
'create-admin-account',
1920
'install',
2021
'success',
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
'use strict';
7+
angular.module('configure-catalog-search', ['ngStorage', 'ngSanitize'])
8+
.controller('configureCatalogSearchController', ['$scope', '$localStorage' , '$state', '$http', function ($scope, $localStorage, $state, $http) {
9+
$scope.search = {
10+
config: {
11+
engine: null,
12+
elasticsearch: {},
13+
},
14+
testConnection: {
15+
result: {}
16+
},
17+
};
18+
19+
if ($localStorage.search) {
20+
$scope.search.config = $localStorage.search;
21+
}
22+
23+
$scope.$on('nextState', function () {
24+
$localStorage.search = $scope.search.config;
25+
});
26+
27+
// Listens on form validate event, dispatched by parent controller
28+
$scope.$on('validate-' + $state.current.id, function() {
29+
$scope.validate();
30+
});
31+
32+
// Dispatch 'validation-response' event to parent controller
33+
$scope.validate = function() {
34+
if ($scope.searchConfig.$valid) {
35+
$scope.$emit('validation-response', true);
36+
} else {
37+
$scope.$emit('validation-response', false);
38+
$scope.searchConfig.submitted = true;
39+
}
40+
};
41+
42+
// Update 'submitted' flag
43+
$scope.$watch(function() { return $scope.searchConfig.$valid }, function(valid) {
44+
if (valid) {
45+
$scope.searchConfig.submitted = false;
46+
}
47+
});
48+
49+
if (!$scope.search.config.engine) {
50+
$http.get('index.php/configure-catalog-search/default-parameters',{'responseType' : 'json'})
51+
.then(function successCallback(resp) {
52+
$scope.search.config = resp.data;
53+
});
54+
}
55+
56+
$scope.testConnection = function(goNext) {
57+
$scope.checking = true;
58+
$scope.search.testConnection.result = {};
59+
$http.post('index.php/search-engine-check', $scope.search.config)
60+
.then(function successCallback(resp) {
61+
if (resp.data.success) {
62+
$scope.search.testConnection.result.success = true;
63+
if (goNext) {
64+
$scope.nextState();
65+
} else {
66+
$scope.search.testConnection.result.message = 'Test connection successful.';
67+
}
68+
} else {
69+
$scope.search.testConnection.result.success = false;
70+
$scope.search.testConnection.result.message = resp.data.error;
71+
}
72+
$scope.checking = false;
73+
}, function errorCallback() {
74+
$scope.search.testConnection.result.success = false;
75+
$scope.search.testConnection.result.message =
76+
'An unknown error occurred. Please check configuration and try again.';
77+
$scope.checking = false;
78+
});
79+
}
80+
}]);

setup/pub/magento/setup/install.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ angular.module('install', ['ngStorage'])
7070
'db': $localStorage.db,
7171
'admin': $localStorage.admin,
7272
'store': $localStorage.store,
73-
'config': $localStorage.config
73+
'config': $localStorage.config,
74+
'search': $localStorage.search
7475
};
7576
$scope.isStarted = true;
7677
$scope.isInProgress = true;

setup/pub/styles/setup.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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+
namespace Magento\Setup\Controller;
7+
8+
use Magento\Setup\Model\SearchConfigOptionsList;
9+
use Laminas\Mvc\Controller\AbstractActionController;
10+
use Laminas\View\Model\ViewModel;
11+
use Laminas\View\Model\JsonModel;
12+
13+
/**
14+
* ConfigureCatalogSearch controller
15+
*/
16+
class ConfigureCatalogSearch extends AbstractActionController
17+
{
18+
/**
19+
* @var SearchConfigOptionsList
20+
*/
21+
private $searchConfigOptionsList;
22+
23+
/**
24+
* @param SearchConfigOptionsList $searchConfigOptionsList
25+
*/
26+
public function __construct(SearchConfigOptionsList $searchConfigOptionsList)
27+
{
28+
$this->searchConfigOptionsList = $searchConfigOptionsList;
29+
}
30+
31+
/**
32+
* Index action
33+
*
34+
* @return ViewModel
35+
*/
36+
public function indexAction()
37+
{
38+
$view = new ViewModel([
39+
'availableSearchEngines' => $this->searchConfigOptionsList->getAvailableSearchEngineList(),
40+
]);
41+
$view->setTerminal(true);
42+
return $view;
43+
}
44+
45+
/**
46+
* Fetch default configuration parameters
47+
*
48+
* @return JsonModel
49+
*/
50+
public function defaultParametersAction()
51+
{
52+
$defaults = [
53+
'engine' => SearchConfigOptionsList::DEFAULT_SEARCH_ENGINE,
54+
'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,
59+
'enableAuth' => false,
60+
'username' => null,
61+
'password' => null
62+
]
63+
];
64+
65+
return new JsonModel($defaults);
66+
}
67+
68+
public function saveAction()
69+
{
70+
71+
}
72+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Setup\Controller;
7+
8+
use Laminas\Json\Json;
9+
use Laminas\Mvc\Controller\AbstractActionController;
10+
use Laminas\View\Model\JsonModel;
11+
use Magento\Setup\Validator\ElasticsearchConnectionValidator;
12+
13+
/**
14+
* SearchEngineCheck controller
15+
*/
16+
class SearchEngineCheck extends AbstractActionController
17+
{
18+
/**
19+
* @var ElasticsearchConnectionValidator
20+
*/
21+
private $connectionValidator;
22+
23+
/**
24+
* @param ElasticsearchConnectionValidator $connectionValidator
25+
*/
26+
public function __construct(ElasticsearchConnectionValidator $connectionValidator)
27+
{
28+
$this->connectionValidator = $connectionValidator;
29+
}
30+
31+
/**
32+
* Result of checking Elasticsearch connection
33+
*
34+
* @return JsonModel
35+
*/
36+
public function indexAction()
37+
{
38+
try {
39+
$params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
40+
$this->connectionValidator->isValidConnection(
41+
[
42+
'hostname' => $params['elasticsearch']['hostname'] ?? null,
43+
'port' => $params['elasticsearch']['port'] ?? null,
44+
'enableAuth' => $params['elasticsearch']['enableAuth'] ?? false,
45+
'username' => $params['elasticsearch']['username'] ?? null,
46+
'password' => $params['elasticsearch']['password'] ?? null,
47+
'indexPrefix' => $params['elasticsearch']['indexPrefix'] ?? ''
48+
]
49+
);
50+
return new JsonModel(['success' => true]);
51+
} catch (\Exception $e) {
52+
return new JsonModel(['success' => false, 'error' => $e->getMessage()]);
53+
}
54+
}
55+
}

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function convert(array $source)
2626
$result = array_merge(
2727
$this->convertDeploymentConfigForm($source),
2828
$this->convertUserConfigForm($source),
29-
$this->convertAdminUserForm($source)
29+
$this->convertAdminUserForm($source),
30+
$this->convertSearchConfigForm($source)
3031
);
3132
return $result;
3233
}
@@ -122,4 +123,39 @@ private function convertAdminUserForm(array $source)
122123
$result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USER];
123124
return $result;
124125
}
126+
127+
/**
128+
* Convert data from request to format of search config model
129+
*
130+
* @param array $source
131+
* @return array
132+
*/
133+
private function convertSearchConfigForm(array $source): array
134+
{
135+
$result = [];
136+
$result[SearchConfigOptionsList::INPUT_KEY_SEARCH_ENGINE] =
137+
isset($source['search']['engine']) ? $source['search']['engine'] : '';
138+
139+
$esConfig = $source['search']['elasticsearch'];
140+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_HOST] =
141+
isset($esConfig['hostname']) ? $esConfig['hostname'] : '';
142+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_PORT] =
143+
isset($esConfig['port']) ? $esConfig['port'] : '';
144+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_INDEX_PREFIX] =
145+
isset($esConfig['indexPrefix']) ? $esConfig['indexPrefix'] : '';
146+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_TIMEOUT] =
147+
isset($esConfig['timeout']) ? $esConfig['timeout'] : '';
148+
if (isset($esConfig['enableAuth']) && true === $esConfig['enableAuth']) {
149+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_ENABLE_AUTH] = $esConfig['enableAuth'];
150+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_USERNAME] =
151+
isset($esConfig['username']) ? $esConfig['username'] : '';
152+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_PASSWORD] =
153+
isset($esConfig['password']) ? $esConfig['password'] : '';
154+
} else {
155+
$result[SearchConfigOptionsList::INPUT_KEY_ELASTICSEARCH_ENABLE_AUTH] =
156+
isset($esConfig['enableAuth']) ? $esConfig['enableAuth'] : false;
157+
}
158+
159+
return $result;
160+
}
125161
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,18 @@ public function getOptionsList(): array
111111
)
112112
];
113113
}
114+
115+
/**
116+
* Get UI friendly list of available search engines
117+
*
118+
* @return array
119+
*/
120+
public function getAvailableSearchEngineList(): array
121+
{
122+
return [
123+
'elasticsearch5' => 'Elasticsearch 5.x (deprecated)',
124+
'elasticsearch6' => 'Elasticsearch 6.x',
125+
'elasticsearch7' => 'Elasticsearch 7.x'
126+
];
127+
}
114128
}

0 commit comments

Comments
 (0)