Skip to content

Commit

Permalink
ENGCOM-1360: [Forwardport] Add argument on app:config:dump to skip du…
Browse files Browse the repository at this point in the history
…mping all system settings. #14807
  • Loading branch information
VladimirZaets authored May 3, 2018
2 parents ae5cda8 + 5c4c91c commit 33e26f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -20,6 +21,8 @@
*/
class ApplicationDumpCommand extends Command
{
const INPUT_CONFIG_TYPES = 'config-types';

/**
* @var Writer
*/
Expand Down Expand Up @@ -47,10 +50,10 @@ public function __construct(
array $sources,
Hash $configHash = null
) {
parent::__construct();
$this->writer = $writer;
$this->sources = $sources;
$this->configHash = $configHash ?: ObjectManager::getInstance()->get(Hash::class);
parent::__construct();
}

/**
Expand All @@ -60,6 +63,13 @@ protected function configure()
{
$this->setName('app:config:dump');
$this->setDescription('Create dump of application');

$configTypes = array_unique(array_column($this->sources, 'namespace'));
$this->addArgument(
self::INPUT_CONFIG_TYPES,
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
sprintf('Space-separated list of config types or omit to dump all [%s]', implode(', ', $configTypes))
);
parent::configure();
}

Expand All @@ -74,11 +84,14 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->groupSourcesByPool();

$dumpedTypes = [];
foreach ($this->sources as $pool => $sources) {
$dump = [];
$comments = [];
foreach ($sources as $sourceData) {
if ($this->skipDump($input, $sourceData)) {
continue;
}
/** @var ConfigSourceInterface $source */
$source = $sourceData['source'];
$namespace = $sourceData['namespace'];
Expand All @@ -95,15 +108,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
null,
$comments
);
$dumpedTypes = array_unique($dumpedTypes + array_keys($dump));
if (!empty($comments)) {
$output->writeln($comments);
}
}

if (!$dumpedTypes) {
$output->writeln('<error>Nothing dumped. Check the config types specified and try again');
return Cli::RETURN_FAILURE;
}

// Generate and save new hash of deployment configuration.
$this->configHash->regenerate();

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

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

$this->sources = $sources;
}

/**
* Check whether the dump source should be skipped
*
* @param InputInterface $input
* @param array $sourceData
* @return bool
*/
private function skipDump(InputInterface $input, array $sourceData): bool
{
$allowedTypes = $input->getArgument(self::INPUT_CONFIG_TYPES);
if ($allowedTypes && !in_array($sourceData['namespace'], $allowedTypes)) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function testExport()
->method('writeln')
->withConsecutive(
[['system' => 'Some comment message']],
['<info>Done.</info>']
['<info>Done. Config types dumped: system</info>']
);

$method = new \ReflectionMethod(ApplicationDumpCommand::class, 'execute');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testExecute()
->with(['system' => $comment]);
$outputMock->expects($this->at(1))
->method('writeln')
->with('<info>Done.</info>');
->with($this->matchesRegularExpression('/<info>Done. Config types dumped: [a-z0-9,\s]+<\/info>/'));

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

0 comments on commit 33e26f3

Please sign in to comment.