Skip to content

Commit 4f574d6

Browse files
committed
MAGETWO-29463: Missing installation features of the new setup wizard - Save Session Data
- added dropdown to select session-save - added validation in case redis is selected.
1 parent f920640 commit 4f574d6

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

setup/pub/magento/setup/web-configuration.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ angular.module('web-configuration', ['ngStorage'])
2727
},
2828
advanced: {
2929
expanded: false
30+
},
31+
sessionSave: {
32+
type: 'files',
33+
error: false
3034
}
3135
};
3236

@@ -115,4 +119,36 @@ angular.module('web-configuration', ['ngStorage'])
115119
$scope.webconfig.submitted = false;
116120
}
117121
});
118-
}]);
122+
}])
123+
.factory('redisFactory', function($http) {
124+
var hasRedisExtension = function() {
125+
return $http.get('index.php/web-configuration/has-redis').success(function (data) {
126+
return data;
127+
})
128+
}
129+
return { hasRedisExtension: hasRedisExtension }
130+
})
131+
.directive('checkRedis', ['redisFactory', function (redisFactory) {
132+
return {
133+
restrict: 'A',
134+
require: 'ngModel',
135+
link: function (scope, element, attrs, ngModel) {
136+
var validator = function(value){
137+
if (value === 'redis' ) {
138+
var ajaxPromise = redisFactory.hasRedisExtension();
139+
ajaxPromise.then(function(result) {
140+
ngModel.$setValidity('checkRedis', result.data.hasRedis);
141+
scope.validate();
142+
})
143+
} else {
144+
ngModel.$setValidity('checkRedis', true);
145+
scope.validate();
146+
}
147+
return value;
148+
};
149+
150+
ngModel.$parsers.unshift(validator);
151+
ngModel.$formatters.unshift(validator);
152+
}
153+
};
154+
}]);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ private function importDeploymentConfigForm()
162162
? $source['config']['address']['admin'] : '';
163163
$result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key'])
164164
? $source['config']['encrypt']['key'] : null;
165+
$result[SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE] = isset($source['config']['sessionSave']['type'])
166+
? $source['config']['sessionSave']['type'] : SetupConfigOptionsList::SESSION_SAVE_FILES;
165167
$result[Installer::ENABLE_MODULES] = isset($source['store']['selectedModules'])
166168
? implode(',', $source['store']['selectedModules']) : '';
167169
$result[Installer::DISABLE_MODULES] = isset($source['store']['allModules'])

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\Setup\Controller;
77

8+
use Magento\Framework\App\SetupInfo;
9+
use Magento\Framework\Config\ConfigOptionsListConstants;
810
use Zend\Mvc\Controller\AbstractActionController;
911
use Zend\View\Model\ViewModel;
10-
use Magento\Framework\App\SetupInfo;
12+
use Zend\View\Model\JsonModel;
1113

1214
class WebConfiguration extends AbstractActionController
1315
{
@@ -22,10 +24,27 @@ public function indexAction()
2224
$view = new ViewModel(
2325
[
2426
'autoBaseUrl' => $setupInfo->getProjectUrl(),
25-
'autoAdminPath' => $setupInfo->getProjectAdminPath()
27+
'autoAdminPath' => $setupInfo->getProjectAdminPath(),
28+
'sessionSave' => [
29+
ConfigOptionsListConstants::SESSION_SAVE_FILES,
30+
ConfigOptionsListConstants::SESSION_SAVE_DB,
31+
ConfigOptionsListConstants::SESSION_SAVE_REDIS,
32+
],
2633
]
2734
);
2835
$view->setTerminal(true);
2936
return $view;
3037
}
38+
39+
/**
40+
* Checks if redis extension exists
41+
*
42+
* @return array|JsonModel
43+
*/
44+
public function hasRedisAction()
45+
{
46+
$json = new JsonModel(['hasRedis' => extension_loaded('redis')]);
47+
$json->setTerminal(true);
48+
return $json;
49+
}
3150
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ private function validateSessionSave(array $options)
271271
&& !in_array($options[ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE], $this->validSaveHandlers)
272272
) {
273273
$errors[] = "Invalid session handler '{$options[ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE]}'";
274+
} else if (isset($options[ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE])
275+
&& $options[ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE]
276+
=== ConfigOptionsListConstants::SESSION_SAVE_REDIS
277+
&& !extension_loaded('redis')
278+
) {
279+
$errors[] = "Session handler has been chosen as 'redis', but PHP extension Redis is not loaded";
274280
}
275281

276282
return $errors;

setup/view/magento/setup/web-configuration.phtml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,40 @@ $hints = [
280280
</div>
281281
</div>
282282

283+
<div class="row form-row">
284+
<div class="col-m-3">
285+
<label class="form-label required">
286+
Session Save
287+
</label>
288+
</div>
289+
<div class="col-m-4">
290+
<select
291+
name="session"
292+
class="form-el-select"
293+
ng-model="config.sessionSave.type"
294+
ng-class="{'invalid': webconfig.session.$invalid && webconfig.submitted}"
295+
tooltip-placement="right"
296+
tooltip-html-unsafe="The location of session. You can change this later in Magento Admin."
297+
tooltip-trigger="focus"
298+
tooltip-append-to-body="true"
299+
ng-change="$scope.validate()"
300+
check-Redis
301+
>
302+
<?php foreach ( $this->sessionSave as $value): ?>
303+
<?php echo "<option value=\"" . $value . "\">" . ucfirst($value) . "</option>"; ?>
304+
<?php endforeach; ?>
305+
</select>
306+
307+
<div class="error-container">
308+
<span ng-show="webconfig.session.$error.checkRedis">
309+
Redis PHP extension is not loaded, please follow instructions on
310+
<a href="http://devdocs.magento.com/guides/v2.0/config-guide/redis/config-redis.html"
311+
target="_blank">how to setup Redis</a>,
312+
before selecting this option.
313+
</span>
314+
</div>
315+
</div>
316+
</div>
283317
</div>
284318

285319
</fieldset>

0 commit comments

Comments
 (0)