@@ -18,14 +18,91 @@ class DumbDbCommand extends AbstractCommand
18
18
'bz2 ' => Bzip2Compressor::class,
19
19
];
20
20
21
+ /**
22
+ * Inspired by WP-CLI's DB_Command
23
+ * @see https://github.com/wp-cli/db-command/blob/e9c4e8ab61e99f7fa7e31e584c2b2b5d54d071db/src/DB_Command.php#L1937
24
+ */
25
+ private const ALLOWED_MYSQLDUMP_OPTIONS = [
26
+ 'add-drop-table ' ,
27
+ 'add-locks ' ,
28
+ 'allow-keywords ' ,
29
+ 'apply-slave-statements ' ,
30
+ 'bind-address ' ,
31
+ 'character-sets-dir ' ,
32
+ 'comments ' ,
33
+ 'compatible ' ,
34
+ 'compact ' ,
35
+ 'complete-insert ' ,
36
+ 'create-options ' ,
37
+ 'databases ' ,
38
+ 'debug ' ,
39
+ 'debug-check ' ,
40
+ 'debug-info ' ,
41
+ 'default-character-set ' ,
42
+ 'delete-master-logs ' ,
43
+ 'disable-keys ' ,
44
+ 'dump-slave ' ,
45
+ 'events ' ,
46
+ 'extended-insert ' ,
47
+ 'fields-terminated-by ' ,
48
+ 'fields-enclosed-by ' ,
49
+ 'fields-optionally-enclosed-by ' ,
50
+ 'fields-escaped-by ' ,
51
+ 'flush-logs ' ,
52
+ 'flush-privileges ' ,
53
+ 'force ' ,
54
+ 'hex-blob ' ,
55
+ 'host ' ,
56
+ 'insert-ignore ' ,
57
+ 'lines-terminated-by ' ,
58
+ 'lock-all-tables ' ,
59
+ 'lock-tables ' ,
60
+ 'log-error ' ,
61
+ 'master-data ' ,
62
+ 'max-allowed-packet ' ,
63
+ 'net-buffer-length ' ,
64
+ 'no-autocommit ' ,
65
+ 'no-create-db ' ,
66
+ 'no-create-info ' ,
67
+ 'no-set-names ' ,
68
+ 'no-tablespaces ' ,
69
+ 'opt ' ,
70
+ 'order-by-primary ' ,
71
+ 'port ' ,
72
+ 'protocol ' ,
73
+ 'quick ' ,
74
+ 'quote-names ' ,
75
+ 'replace ' ,
76
+ 'routines ' ,
77
+ 'set-charset ' ,
78
+ 'single-transaction ' ,
79
+ 'dump-date ' ,
80
+ 'skip-comments ' ,
81
+ 'skip-opt ' ,
82
+ 'socket ' ,
83
+ 'ssl ' ,
84
+ 'ssl-ca ' ,
85
+ 'ssl-capath ' ,
86
+ 'ssl-cert ' ,
87
+ 'ssl-cipher ' ,
88
+ 'ssl-key ' ,
89
+ 'ssl-verify-server-cert ' ,
90
+ 'tab ' ,
91
+ 'triggers ' ,
92
+ 'tz-utc ' ,
93
+ 'user ' ,
94
+ 'where ' ,
95
+ 'xml ' ,
96
+ ];
97
+
21
98
public function __construct (protected Config $ config , protected Paths $ paths )
22
99
{
23
100
parent ::__construct ();
24
101
}
25
102
26
103
protected function configure (): void
27
104
{
28
- $ this
105
+ $ command = $ this
29
106
->setName ('db:dump ' )
30
107
->setDescription ('Dump the contents of a database ' )
31
108
->addArgument (
@@ -81,6 +158,15 @@ protected function configure(): void
81
158
InputOption::VALUE_NONE ,
82
159
'Do not use column statistics (for MySQL 8 compatibility with older versions) ' ,
83
160
);
161
+
162
+ foreach (self ::ALLOWED_MYSQLDUMP_OPTIONS as $ option ) {
163
+ $ command ->addOption (
164
+ $ option ,
165
+ null ,
166
+ InputOption::VALUE_OPTIONAL ,
167
+ "Pass -- $ option to mysqldump " ,
168
+ );
169
+ }
84
170
}
85
171
86
172
/**
@@ -150,6 +236,17 @@ protected function fire(): int
150
236
$ dumper ->doNotUseColumnStatistics ();
151
237
}
152
238
239
+ foreach (self ::ALLOWED_MYSQLDUMP_OPTIONS as $ option ) {
240
+ $ value = $ this ->input ->getOption ($ option );
241
+ if ($ value !== null ) {
242
+ if ($ value === true || $ value === '' ) {
243
+ $ dumper ->addExtraOption ("-- $ option " );
244
+ } else {
245
+ $ dumper ->addExtraOption ("-- $ option= " .$ value );
246
+ }
247
+ }
248
+ }
249
+
153
250
try {
154
251
$ dumper ->dumpToFile ($ path );
155
252
$ this ->info ("Database dumped successfully to: $ path " );
0 commit comments