Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument on app:config:dump to skip dumping all system settings. #12410

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('<info>Done. Config types dumped: scopes, themes, system, i18n</info>');

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