Skip to content

Commit 73af74a

Browse files
author
Stanislav Idolov
authored
MAGETWO-84651: Add argument on app:config:dump to skip dumping all system settings. #12410
2 parents b39852c + f8f280d commit 73af74a

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

app/code/Magento/Deploy/Console/Command/App/ApplicationDumpCommand.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Config\File\ConfigFilePool;
1313
use Magento\Framework\Console\Cli;
1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Output\OutputInterface;
1718

@@ -20,6 +21,8 @@
2021
*/
2122
class ApplicationDumpCommand extends Command
2223
{
24+
const INPUT_CONFIG_TYPES = 'config-types';
25+
2326
/**
2427
* @var Writer
2528
*/
@@ -47,10 +50,10 @@ public function __construct(
4750
array $sources,
4851
Hash $configHash = null
4952
) {
50-
parent::__construct();
5153
$this->writer = $writer;
5254
$this->sources = $sources;
5355
$this->configHash = $configHash ?: ObjectManager::getInstance()->get(Hash::class);
56+
parent::__construct();
5457
}
5558

5659
/**
@@ -60,6 +63,13 @@ protected function configure()
6063
{
6164
$this->setName('app:config:dump');
6265
$this->setDescription('Create dump of application');
66+
67+
$configTypes = array_unique(array_column($this->sources, 'namespace'));
68+
$this->addArgument(
69+
self::INPUT_CONFIG_TYPES,
70+
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
71+
sprintf('Space-separated list of config types or omit to dump all [%s]', implode(', ', $configTypes))
72+
);
6373
parent::configure();
6474
}
6575

@@ -74,11 +84,14 @@ protected function configure()
7484
protected function execute(InputInterface $input, OutputInterface $output)
7585
{
7686
$this->groupSourcesByPool();
77-
87+
$dumpedTypes = [];
7888
foreach ($this->sources as $pool => $sources) {
7989
$dump = [];
8090
$comments = [];
8191
foreach ($sources as $sourceData) {
92+
if ($this->skipDump($input, $sourceData)) {
93+
continue;
94+
}
8295
/** @var ConfigSourceInterface $source */
8396
$source = $sourceData['source'];
8497
$namespace = $sourceData['namespace'];
@@ -95,15 +108,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
95108
null,
96109
$comments
97110
);
111+
$dumpedTypes = array_unique($dumpedTypes + array_keys($dump));
98112
if (!empty($comments)) {
99113
$output->writeln($comments);
100114
}
101115
}
102116

117+
if (!$dumpedTypes) {
118+
$output->writeln('<error>Nothing dumped. Check the config types specified and try again');
119+
return Cli::RETURN_FAILURE;
120+
}
121+
103122
// Generate and save new hash of deployment configuration.
104123
$this->configHash->regenerate();
105124

106-
$output->writeln('<info>Done.</info>');
125+
$output->writeln(sprintf('<info>Done. Config types dumped: %s</info>', implode(', ', $dumpedTypes)));
107126
return Cli::RETURN_SUCCESS;
108127
}
109128

@@ -127,4 +146,20 @@ private function groupSourcesByPool()
127146

128147
$this->sources = $sources;
129148
}
149+
150+
/**
151+
* Check whether the dump source should be skipped
152+
*
153+
* @param InputInterface $input
154+
* @param array $sourceData
155+
* @return bool
156+
*/
157+
private function skipDump(InputInterface $input, array $sourceData): bool
158+
{
159+
$allowedTypes = $input->getArgument(self::INPUT_CONFIG_TYPES);
160+
if ($allowedTypes && !in_array($sourceData['namespace'], $allowedTypes)) {
161+
return true;
162+
}
163+
return false;
164+
}
130165
}

app/code/Magento/Deploy/Test/Unit/Console/Command/ApplicationDumpCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function testExport()
130130
->method('writeln')
131131
->withConsecutive(
132132
[['system' => 'Some comment message']],
133-
['<info>Done.</info>']
133+
['<info>Done. Config types dumped: system</info>']
134134
);
135135

136136
$method = new \ReflectionMethod(ApplicationDumpCommand::class, 'execute');

dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/ApplicationDumpCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function testExecute()
176176
->with(['system' => $comment]);
177177
$outputMock->expects($this->at(1))
178178
->method('writeln')
179-
->with('<info>Done.</info>');
179+
->with('<info>Done. Config types dumped: scopes, themes, system, i18n</info>');
180180

181181
/** @var ApplicationDumpCommand command */
182182
$command = $this->objectManager->create(ApplicationDumpCommand::class);

0 commit comments

Comments
 (0)