1212use Magento \Framework \Config \File \ConfigFilePool ;
1313use Magento \Framework \Console \Cli ;
1414use Symfony \Component \Console \Command \Command ;
15+ use Symfony \Component \Console \Input \InputArgument ;
1516use Symfony \Component \Console \Input \InputInterface ;
1617use Symfony \Component \Console \Output \OutputInterface ;
1718
2021 */
2122class ApplicationDumpCommand extends Command
2223{
24+ const INPUT_CONFIG_TYPES = 'config-types ' ;
25+
26+ /**
27+ * @var array
28+ */
29+ private $ configTypes = [
30+ \Magento \Store \App \Config \Type \Scopes::CONFIG_TYPE ,
31+ \Magento \Deploy \Source \Themes::TYPE ,
32+ \Magento \Translation \App \Config \Type \Translation::CONFIG_TYPE ,
33+ \Magento \Config \App \Config \Type \System::CONFIG_TYPE ,
34+ ];
35+
2336 /**
2437 * @var Writer
2538 */
@@ -60,6 +73,12 @@ protected function configure()
6073 {
6174 $ this ->setName ('app:config:dump ' );
6275 $ this ->setDescription ('Create dump of application ' );
76+ $ this ->addArgument (
77+ self ::INPUT_CONFIG_TYPES ,
78+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
79+ sprintf ('Space-separated list of config types or omit to dump all [%s] ' ,
80+ implode (', ' , $ this ->configTypes ))
81+ );
6382 parent ::configure ();
6483 }
6584
@@ -74,11 +93,14 @@ protected function configure()
7493 protected function execute (InputInterface $ input , OutputInterface $ output )
7594 {
7695 $ this ->groupSourcesByPool ();
77-
96+ $ dumpedTypes = [];
7897 foreach ($ this ->sources as $ pool => $ sources ) {
7998 $ dump = [];
8099 $ comments = [];
81100 foreach ($ sources as $ sourceData ) {
101+ if ($ this ->skipDump ($ input , $ sourceData )) {
102+ continue ;
103+ }
82104 /** @var ConfigSourceInterface $source */
83105 $ source = $ sourceData ['source ' ];
84106 $ namespace = $ sourceData ['namespace ' ];
@@ -95,15 +117,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
95117 null ,
96118 $ comments
97119 );
120+ $ dumpedTypes = array_unique ($ dumpedTypes + array_keys ($ dump ));
98121 if (!empty ($ comments )) {
99122 $ output ->writeln ($ comments );
100123 }
101124 }
102125
126+ if (!$ dumpedTypes ) {
127+ $ output ->writeln ('<error>Nothing dumped. Check the config types specified and try again ' );
128+ return Cli::RETURN_FAILURE ;
129+ }
130+
103131 // Generate and save new hash of deployment configuration.
104132 $ this ->configHash ->regenerate ();
105133
106- $ output ->writeln ('<info>Done.</info> ' );
134+ $ output ->writeln (sprintf ( '<info>Done. Config types dumped: %s </info> ' , implode ( ' , ' , $ dumpedTypes )) );
107135 return Cli::RETURN_SUCCESS ;
108136 }
109137
@@ -127,4 +155,20 @@ private function groupSourcesByPool()
127155
128156 $ this ->sources = $ sources ;
129157 }
158+
159+ /**
160+ * Check whether the dump source should be skipped
161+ *
162+ * @param InputInterface $input
163+ * @param array $sourceData
164+ * @return bool
165+ */
166+ private function skipDump (InputInterface $ input , array $ sourceData ): bool
167+ {
168+ $ allowedTypes = $ input ->getArgument (self ::INPUT_CONFIG_TYPES );
169+ if ($ allowedTypes && !in_array ($ sourceData ['namespace ' ], $ allowedTypes )) {
170+ return true ;
171+ }
172+ return false ;
173+ }
130174}
0 commit comments