12
12
use Magento \Framework \Config \File \ConfigFilePool ;
13
13
use Magento \Framework \Console \Cli ;
14
14
use Symfony \Component \Console \Command \Command ;
15
+ use Symfony \Component \Console \Input \InputArgument ;
15
16
use Symfony \Component \Console \Input \InputInterface ;
16
17
use Symfony \Component \Console \Output \OutputInterface ;
17
18
20
21
*/
21
22
class ApplicationDumpCommand extends Command
22
23
{
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
+
23
36
/**
24
37
* @var Writer
25
38
*/
@@ -60,6 +73,12 @@ protected function configure()
60
73
{
61
74
$ this ->setName ('app:config:dump ' );
62
75
$ 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
+ );
63
82
parent ::configure ();
64
83
}
65
84
@@ -74,11 +93,14 @@ protected function configure()
74
93
protected function execute (InputInterface $ input , OutputInterface $ output )
75
94
{
76
95
$ this ->groupSourcesByPool ();
77
-
96
+ $ dumpedTypes = [];
78
97
foreach ($ this ->sources as $ pool => $ sources ) {
79
98
$ dump = [];
80
99
$ comments = [];
81
100
foreach ($ sources as $ sourceData ) {
101
+ if ($ this ->skipDump ($ input , $ sourceData )) {
102
+ continue ;
103
+ }
82
104
/** @var ConfigSourceInterface $source */
83
105
$ source = $ sourceData ['source ' ];
84
106
$ namespace = $ sourceData ['namespace ' ];
@@ -95,15 +117,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
95
117
null ,
96
118
$ comments
97
119
);
120
+ $ dumpedTypes = array_unique ($ dumpedTypes + array_keys ($ dump ));
98
121
if (!empty ($ comments )) {
99
122
$ output ->writeln ($ comments );
100
123
}
101
124
}
102
125
126
+ if (!$ dumpedTypes ) {
127
+ $ output ->writeln ('<error>Nothing dumped. Check the config types specified and try again ' );
128
+ return Cli::RETURN_FAILURE ;
129
+ }
130
+
103
131
// Generate and save new hash of deployment configuration.
104
132
$ this ->configHash ->regenerate ();
105
133
106
- $ output ->writeln ('<info>Done.</info> ' );
134
+ $ output ->writeln (sprintf ( '<info>Done. Config types dumped: %s </info> ' , implode ( ' , ' , $ dumpedTypes )) );
107
135
return Cli::RETURN_SUCCESS ;
108
136
}
109
137
@@ -127,4 +155,20 @@ private function groupSourcesByPool()
127
155
128
156
$ this ->sources = $ sources ;
129
157
}
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
+ }
130
174
}
0 commit comments