Skip to content

Commit

Permalink
Add argument on app:config:dump to specify which types to dump. That …
Browse files Browse the repository at this point in the history
…allows to dump only scope and theme while skipping system for easier maintainability.
  • Loading branch information
jalogut authored and ihor-sviziev committed Apr 23, 2018
1 parent 782bc0e commit 2631805
Showing 1 changed file with 46 additions and 2 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,18 @@
*/
class ApplicationDumpCommand extends Command
{
const INPUT_CONFIG_TYPES = 'config-types';

/**
* @var array
*/
private $configTypes = [
\Magento\Store\App\Config\Type\Scopes::CONFIG_TYPE,
\Magento\Deploy\Source\Themes::TYPE,
\Magento\Translation\App\Config\Type\Translation::CONFIG_TYPE,
\Magento\Config\App\Config\Type\System::CONFIG_TYPE,
];

/**
* @var Writer
*/
Expand Down Expand Up @@ -60,6 +73,12 @@ protected function configure()
{
$this->setName('app:config:dump');
$this->setDescription('Create dump of application');
$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(', ', $this->configTypes))
);
parent::configure();
}

Expand All @@ -74,11 +93,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 +117,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 +155,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;
}
}

0 comments on commit 2631805

Please sign in to comment.