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
+
23
26
/**
24
27
* @var Writer
25
28
*/
@@ -47,10 +50,10 @@ public function __construct(
47
50
array $ sources ,
48
51
Hash $ configHash = null
49
52
) {
50
- parent ::__construct ();
51
53
$ this ->writer = $ writer ;
52
54
$ this ->sources = $ sources ;
53
55
$ this ->configHash = $ configHash ?: ObjectManager::getInstance ()->get (Hash::class);
56
+ parent ::__construct ();
54
57
}
55
58
56
59
/**
@@ -60,6 +63,13 @@ protected function configure()
60
63
{
61
64
$ this ->setName ('app:config:dump ' );
62
65
$ this ->setDescription ('Create dump of application ' );
66
+
67
+ $ configTypes = array_unique (array_column ($ this ->sources , 'namespace ' ));
68
+ $ this ->addArgument (
69
+ self ::INPUT_CONFIG_TYPES ,
70
+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
71
+ sprintf ('Space-separated list of config types or omit to dump all [%s] ' , implode (', ' , $ configTypes ))
72
+ );
63
73
parent ::configure ();
64
74
}
65
75
@@ -74,11 +84,14 @@ protected function configure()
74
84
protected function execute (InputInterface $ input , OutputInterface $ output )
75
85
{
76
86
$ this ->groupSourcesByPool ();
77
-
87
+ $ dumpedTypes = [];
78
88
foreach ($ this ->sources as $ pool => $ sources ) {
79
89
$ dump = [];
80
90
$ comments = [];
81
91
foreach ($ sources as $ sourceData ) {
92
+ if ($ this ->skipDump ($ input , $ sourceData )) {
93
+ continue ;
94
+ }
82
95
/** @var ConfigSourceInterface $source */
83
96
$ source = $ sourceData ['source ' ];
84
97
$ namespace = $ sourceData ['namespace ' ];
@@ -95,15 +108,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
95
108
null ,
96
109
$ comments
97
110
);
111
+ $ dumpedTypes = array_unique ($ dumpedTypes + array_keys ($ dump ));
98
112
if (!empty ($ comments )) {
99
113
$ output ->writeln ($ comments );
100
114
}
101
115
}
102
116
117
+ if (!$ dumpedTypes ) {
118
+ $ output ->writeln ('<error>Nothing dumped. Check the config types specified and try again ' );
119
+ return Cli::RETURN_FAILURE ;
120
+ }
121
+
103
122
// Generate and save new hash of deployment configuration.
104
123
$ this ->configHash ->regenerate ();
105
124
106
- $ output ->writeln ('<info>Done.</info> ' );
125
+ $ output ->writeln (sprintf ( '<info>Done. Config types dumped: %s </info> ' , implode ( ' , ' , $ dumpedTypes )) );
107
126
return Cli::RETURN_SUCCESS ;
108
127
}
109
128
@@ -127,4 +146,20 @@ private function groupSourcesByPool()
127
146
128
147
$ this ->sources = $ sources ;
129
148
}
149
+
150
+ /**
151
+ * Check whether the dump source should be skipped
152
+ *
153
+ * @param InputInterface $input
154
+ * @param array $sourceData
155
+ * @return bool
156
+ */
157
+ private function skipDump (InputInterface $ input , array $ sourceData ): bool
158
+ {
159
+ $ allowedTypes = $ input ->getArgument (self ::INPUT_CONFIG_TYPES );
160
+ if ($ allowedTypes && !in_array ($ sourceData ['namespace ' ], $ allowedTypes )) {
161
+ return true ;
162
+ }
163
+ return false ;
164
+ }
130
165
}
0 commit comments