Skip to content

Commit 17dbc80

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-901' into GL_Mainline_PR_25112021
2 parents 6204718 + 52e5233 commit 17dbc80

File tree

5 files changed

+63
-20
lines changed

5 files changed

+63
-20
lines changed

app/code/Magento/Config/Setup/ConfigOptionsList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public function getOptions()
6161
new SelectConfigOption(
6262
self::INPUT_KEY_DEBUG_LOGGING,
6363
SelectConfigOption::FRONTEND_WIZARD_RADIO,
64-
[true, false, 1, 0],
64+
['true', 'false', 1, 0],
6565
self::CONFIG_PATH_DEBUG_LOGGING,
6666
'Enable debug logging'
6767
),
6868
new SelectConfigOption(
6969
self::INPUT_KEY_SYSLOG_LOGGING,
7070
SelectConfigOption::FRONTEND_WIZARD_RADIO,
71-
[true, false, 1, 0],
71+
['true', 'false', 1, 0],
7272
self::CONFIG_PATH_SYSLOG_LOGGING,
7373
'Enable syslog logging'
7474
),

setup/src/Magento/Setup/Console/Command/InstallCommand.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ class InstallCommand extends AbstractSetupCommand
116116
*/
117117
protected $searchConfigOptionsList;
118118

119+
/**
120+
* @var array
121+
*/
122+
protected $interactiveSetupUserInput;
123+
119124
/**
120125
* Constructor
121126
*
@@ -228,7 +233,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
228233
{
229234
$consoleLogger = new ConsoleLogger($output);
230235
$installer = $this->installerFactory->create($consoleLogger);
231-
$installer->install($input->getOptions());
236+
$isInteractiveSetup = $input->getOption(self::INPUT_KEY_INTERACTIVE_SETUP) ?? false;
237+
$installer->install($isInteractiveSetup ? array_merge($input->getOptions(), $this->interactiveSetupUserInput) :
238+
$input->getOptions());
232239

233240
$importConfigCommand = $this->getApplication()->find(ConfigImportCommand::COMMAND_NAME);
234241
$arrayInput = new ArrayInput([]);
@@ -260,6 +267,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
260267
$command .= " --{$key}={$value}";
261268
}
262269
$output->writeln("<comment>Try re-running command: php bin/magento setup:install{$command}</comment>");
270+
$this->interactiveSetupUserInput = $configOptionsToValidate;
263271
}
264272

265273
$errors = $this->configModel->validate($configOptionsToValidate);
@@ -356,7 +364,7 @@ private function interactiveQuestions(InputInterface $input, OutputInterface $ou
356364
/**
357365
* Runs interactive questions
358366
*
359-
* It will ask users for interactive questionst regarding setup configuration.
367+
* It will ask users for interactive questions regarding setup configuration.
360368
*
361369
* @param InputInterface $input
362370
* @param OutputInterface $output
@@ -403,14 +411,11 @@ private function askQuestion(
403411
$question->setValidator(function ($answer) use ($option, $validateInline) {
404412

405413
if ($option instanceof \Magento\Framework\Setup\Option\SelectConfigOption) {
406-
$answer = $option->getSelectOptions()[$answer];
414+
//If user doesn't provide an input & default value for question is not set, take first option as input.
415+
$answer = $option->getSelectOptions()[$answer] ?? current($option->getSelectOptions());
407416
}
408417

409-
if ($answer == null) {
410-
$answer = '';
411-
} else {
412-
$answer = trim($answer);
413-
}
418+
$answer = $answer === null ? '' : (is_string($answer) ? trim($answer) : $answer);
414419

415420
if ($validateInline) {
416421
$option->validate($answer);

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\DeploymentConfig\Writer;
1212
use Magento\Framework\Setup\Option\AbstractConfigOption;
1313
use Magento\Framework\Setup\FilePermissions;
14+
use Magento\Setup\Exception as SetupException;
1415

1516
class ConfigModel
1617
{
@@ -68,9 +69,11 @@ public function getAvailableOptions()
6869
$optionLists = $this->collector->collectOptionsLists();
6970

7071
foreach ($optionLists as $optionList) {
71-
$optionCollection = array_merge($optionCollection, $optionList->getOptions());
72+
$optionCollection[] = $optionList->getOptions();
7273
}
7374

75+
$optionCollection = array_merge([], ...$optionCollection);
76+
7477
foreach ($optionCollection as $option) {
7578
$currentValue = $this->deploymentConfig->get($option->getConfigPath());
7679
if ($currentValue !== null) {
@@ -100,7 +103,7 @@ public function process($inputOptions)
100103
foreach ($configData as $config) {
101104
$fileConfigStorage = [];
102105
if (!$config instanceof ConfigData) {
103-
throw new \Exception(
106+
throw new SetupException(
104107
'In module : '
105108
. $moduleName
106109
. 'ConfigOption::createConfig should return an array of ConfigData instances'
@@ -134,8 +137,10 @@ public function validate(array $inputOptions)
134137
$options = $this->getAvailableOptions();
135138
foreach ($options as $option) {
136139
try {
137-
if ($inputOptions[$option->getName()] !== null) {
138-
$option->validate($inputOptions[$option->getName()]);
140+
$inputValue = $inputOptions[$option->getName()] ?? null;
141+
142+
if ($inputValue !== null) {
143+
$option->validate($inputValue);
139144
}
140145
} catch (\InvalidArgumentException $e) {
141146
$errors[] = $e->getMessage();
@@ -146,10 +151,10 @@ public function validate(array $inputOptions)
146151
$options = $this->collector->collectOptionsLists();
147152

148153
foreach ($options as $option) {
149-
$errors = array_merge($errors, $option->validate($inputOptions, $this->deploymentConfig));
154+
$errors[] = $option->validate($inputOptions, $this->deploymentConfig);
150155
}
151156

152-
return $errors;
157+
return array_merge([], ...$errors);
153158
}
154159

155160
/**
@@ -163,7 +168,7 @@ private function checkInstallationFilePermissions()
163168
$results = $this->filePermissions->getMissingWritablePathsForInstallation();
164169
if ($results) {
165170
$errorMsg = "Missing write permissions to the following paths:" . PHP_EOL . implode(PHP_EOL, $results);
166-
throw new \Exception($errorMsg);
171+
throw new SetupException($errorMsg);
167172
}
168173
}
169174
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ public function validate(array $options, DeploymentConfig $deploymentConfig)
252252
$errors[] = $this->validateDbPrefix($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX]);
253253
}
254254

255-
if (!$options[ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION]) {
255+
if (isset($options[ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION]) &&
256+
!$options[ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION]) {
256257
$errors[] = $this->validateDbSettings($options, $deploymentConfig);
257258
}
258259

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
1111
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
1212
use Magento\Framework\Config\ConfigOptionsListConstants as SetupConfigOptionsList;
13+
use Magento\Framework\Console\Cli;
1314
use Magento\Framework\Setup\Option\TextConfigOption;
1415
use Magento\Setup\Console\Command\AdminUserCreateCommand;
1516
use Magento\Setup\Console\Command\InstallCommand;
@@ -24,6 +25,7 @@
2425
use Magento\Setup\Model\SearchConfigOptionsList;
2526
use Symfony\Component\Console\Application;
2627
use Symfony\Component\Console\Helper\HelperSet;
28+
use Symfony\Component\Console\Helper\QuestionHelper;
2729
use Symfony\Component\Console\Input\InputDefinition;
2830
use Symfony\Component\Console\Tester\CommandTester;
2931

@@ -77,6 +79,11 @@ class InstallCommandTest extends TestCase
7779
*/
7880
private $adminUserMock;
7981

82+
/**
83+
* @var QuestionHelper
84+
*/
85+
private $questionHelperMock;
86+
8087
protected function setUp(): void
8188
{
8289
$this->input = [
@@ -102,7 +109,7 @@ protected function setUp(): void
102109

103110
$userConfig = $this->createMock(InstallStoreConfigurationCommand::class);
104111
$userConfig
105-
->expects($this->once())
112+
->expects($this->atLeastOnce())
106113
->method('getOptionsList')
107114
->willReturn($this->getOptionsListUserConfig());
108115
$userConfig
@@ -112,7 +119,7 @@ protected function setUp(): void
112119

113120
$this->adminUserMock = $this->createMock(AdminUserCreateCommand::class);
114121
$this->adminUserMock
115-
->expects($this->once())
122+
->expects($this->atLeastOnce())
116123
->method('getOptionsList')
117124
->willReturn($this->getOptionsListAdminUser());
118125

@@ -146,6 +153,10 @@ protected function setUp(): void
146153
->with(ConfigImportCommand::COMMAND_NAME)
147154
->willReturn($this->configImportMock);
148155

156+
$this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class)
157+
->disableOriginalConstructor()
158+
->getMock();
159+
149160
$this->command = new InstallCommand(
150161
$this->installerFactory,
151162
$configModel,
@@ -181,6 +192,27 @@ public function testExecute()
181192
$commandTester->execute($this->input);
182193
}
183194

195+
public function testInteractiveExecute(): void
196+
{
197+
$this->installerFactory
198+
->expects($this->once())
199+
->method('create')
200+
->willReturn($this->installer);
201+
$this->installer
202+
->expects($this->once())
203+
->method('install');
204+
$this->questionHelperMock->method('ask');
205+
$this->helperSetMock
206+
->method('get')
207+
->with('question')
208+
->willReturn($this->questionHelperMock);
209+
$this->command->setHelperSet($this->helperSetMock);
210+
211+
$commandTester = new CommandTester($this->command);
212+
$commandTester->execute(['--' . InstallCommand::INPUT_KEY_INTERACTIVE_SETUP => true]);
213+
$this->assertEquals(Cli::RETURN_SUCCESS, $commandTester->getStatusCode());
214+
}
215+
184216
/**
185217
* Get list of options for deployment configuration
186218
*

0 commit comments

Comments
 (0)