Skip to content

Commit b20380e

Browse files
author
Ivan Gavryshko
committed
MAGETWO-35137: Add deployment configuration set command
- added message that informs is data saved to config or not, also informs if default values are used. - changed confgiOptionsCollector so all options collects even for disabled modules.
1 parent c08ade3 commit b20380e

File tree

4 files changed

+37
-57
lines changed

4 files changed

+37
-57
lines changed

dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@ public function setUp()
2121
->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager());
2222
}
2323

24-
public function testCollectOptionsDeploymentConfigAvailable()
24+
public function testCollectOptionLists()
2525
{
2626
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
27-
$moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false);
28-
$moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(true);
29-
$moduleListMock->expects($this->once())->method('getNames')->willReturn(['Magento_Backend']);
3027
$fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false);
3128
$fullModuleListMock->expects($this->never())->method('getNames');
3229
/** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */
3330
$object = $objectManager->create(
3431
'Magento\Setup\Model\ConfigOptionsListCollector',
3532
[
3633
'objectManagerProvider' => $this->objectManagerProvider,
37-
'moduleList' => $moduleListMock,
3834
'fullModuleList' => $fullModuleListMock,
3935
]
4036
);
@@ -51,30 +47,4 @@ public function testCollectOptionsDeploymentConfigAvailable()
5147
$this->assertEquals($expected, $result);
5248

5349
}
54-
55-
public function testCollectOptionsDeploymentConfigUnavailable()
56-
{
57-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
58-
$moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false);
59-
$moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(false);
60-
$moduleListMock->expects($this->never())->method('getNames');
61-
/** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */
62-
$object = $objectManager->create(
63-
'Magento\Setup\Model\ConfigOptionsListCollector',
64-
[
65-
'objectManagerProvider' => $this->objectManagerProvider,
66-
'moduleList' => $moduleListMock,
67-
]
68-
);
69-
$result = $object->collectOptionLists();
70-
71-
$backendOptions = new \Magento\Backend\Setup\ConfigOptionsList();
72-
$expected = [
73-
'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
74-
->get('Magento\Framework\Config\ConfigOptionsList'),
75-
'Magento_Backend' => $backendOptions,
76-
];
77-
78-
$this->assertEquals($expected, $result);
79-
}
8050
}

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
{
7474
$inputOptions = $input->getOptions();
7575
$optionCollection = $this->configModel->getAvailableOptions();
76+
$optionsToChange = [];
77+
$optionsWithDefaultValues = [];
78+
7679
foreach ($optionCollection as $option) {
7780
$currentValue = $this->deploymentConfig->get($option->getConfigPath());
7881
if (($currentValue !== null) && ($inputOptions[$option->getName()] !== null)) {
@@ -82,30 +85,48 @@ protected function execute(InputInterface $input, OutputInterface $output)
8285
'<question>Overwrite the existing configuration for ' . $option->getName() . '?[Y|n]</question>'
8386
)) {
8487
$inputOptions[$option->getName()] = null;
88+
} else {
89+
$optionsToChange[$option->getName()] = $inputOptions[$option->getName()];
90+
}
91+
} else {
92+
if ($inputOptions[$option->getName()] !== null) {
93+
$optionsToChange[$option->getName()] = $inputOptions[$option->getName()];
8594
}
8695
}
96+
if ($option->getDefault() === $inputOptions[$option->getName()]
97+
&& $inputOptions[$option->getName()] !== null
98+
) {
99+
$optionsWithDefaultValues[] = $option->getName();
100+
}
87101
}
102+
88103
$inputOptions = array_filter(
89104
$inputOptions,
90105
function ($value) {
91106
return $value !== null;
92107
}
93108
);
109+
94110
$this->configModel->process($inputOptions);
95-
$output->writeln('<info>You saved the deployment config.</info>');
111+
if (count($optionsWithDefaultValues) > 0) {
112+
$defaultValuesMessage = implode(', ', $optionsWithDefaultValues);
113+
$output->writeln(
114+
'<info>You saved default value(s) for the next option(s): ' . $defaultValuesMessage . '.</info>'
115+
);
116+
} else {
117+
if (count($optionsToChange) > 0) {
118+
$output->writeln('<info>You saved the deployment config.</info>');
119+
} else {
120+
$output->writeln('<info>You did not save the deployment config.</info>');
121+
}
122+
}
96123
}
97124

98125
/**
99126
* {@inheritdoc}
100127
*/
101128
protected function initialize(InputInterface $input, OutputInterface $output)
102129
{
103-
if (!$this->moduleList->isModuleInfoAvailable()) {
104-
$output->writeln(
105-
'<info>No module configuration is available, so all modules are enabled.</info>'
106-
);
107-
}
108-
109130
$inputOptions = $input->getOptions();
110131

111132
$errors = $this->configModel->validate($inputOptions);

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\Filesystem;
1010
use Magento\Framework\Module\FullModuleList;
11-
use Magento\Framework\Module\ModuleList;
1211
use Magento\Framework\Setup\ConfigOptionsListInterface;
1312

1413
/**
@@ -37,13 +36,6 @@ class ConfigOptionsListCollector
3736
*/
3837
private $fullModuleList;
3938

40-
/**
41-
* Enabled module list
42-
*
43-
* @var ModuleList
44-
*/
45-
private $moduleList;
46-
4739
/**
4840
* Object manager provider
4941
*
@@ -57,38 +49,32 @@ class ConfigOptionsListCollector
5749
* @param DirectoryList $directoryList
5850
* @param Filesystem $filesystem
5951
* @param FullModuleList $fullModuleList
60-
* @param ModuleList $moduleList
6152
* @param ObjectManagerProvider $objectManagerProvider
6253
*/
6354
public function __construct(
6455
DirectoryList $directoryList,
6556
Filesystem $filesystem,
6657
FullModuleList $fullModuleList,
67-
ModuleList $moduleList,
6858
ObjectManagerProvider $objectManagerProvider
6959
) {
7060
$this->directoryList = $directoryList;
7161
$this->filesystem = $filesystem;
7262
$this->fullModuleList = $fullModuleList;
73-
$this->moduleList = $moduleList;
7463
$this->objectManagerProvider = $objectManagerProvider;
7564
}
7665

7766
/**
7867
* Auto discover ConfigOptionsList class and collect them.
7968
* These classes should reside in <module>/Setup directories.
80-
* If deployment config is not available, all modules will be searched. Otherwise, only enabled modules
81-
* will be searched.
8269
*
8370
* @return \Magento\Framework\Setup\ConfigOptionsListInterface[]
8471
*/
8572
public function collectOptionLists()
8673
{
8774
$optionsList = [];
8875

89-
$moduleList = $this->moduleList->isModuleInfoAvailable() ? $this->moduleList : $this->fullModuleList;
9076
// go through modules
91-
foreach ($moduleList->getNames() as $moduleName) {
77+
foreach ($this->fullModuleList->getNames() as $moduleName) {
9278
$optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptionsList';
9379
if (class_exists($optionsClassName)) {
9480
$optionsClass = $this->objectManagerProvider->get()->create($optionsClassName);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public function testExecuteNoInteractive()
5959
$commandTester = new CommandTester($this->command);
6060
$commandTester->execute(['--db_host' => 'host']);
6161
$this->assertSame(
62-
'No module configuration is available, so all modules are enabled.' . PHP_EOL
63-
. 'You saved the deployment config.' . PHP_EOL,
62+
'You saved the deployment config.' . PHP_EOL,
6463
$commandTester->getDisplay()
6564
);
6665
}
@@ -116,9 +115,13 @@ private function checkInteraction($interactionType)
116115

117116
$commandTester = new CommandTester($this->command);
118117
$commandTester->execute(['--db_host' => 'host']);
118+
if ($interactionType) {
119+
$message = 'You saved the deployment config.' . PHP_EOL;
120+
} else {
121+
$message = 'You did not save the deployment config.'.PHP_EOL;
122+
}
119123
$this->assertSame(
120-
'No module configuration is available, so all modules are enabled.' . PHP_EOL
121-
. 'You saved the deployment config.' . PHP_EOL,
124+
$message,
122125
$commandTester->getDisplay()
123126
);
124127
}

0 commit comments

Comments
 (0)