Skip to content

Commit 0c7ad26

Browse files
authored
Merge pull request #21 from bstanley-pec/feat/remove-mysql-password-warning
Suppress mysql warning about insecure password
2 parents 3083e68 + e49ecd1 commit 0c7ad26

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Commands/MigrateDumpCommand.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ public static function reorderMigrationRows(array $output) : array
142142
*/
143143
private static function mysqlSchemaDump(array $db_config, string $schema_sql_path) : int
144144
{
145-
// TODO: Suppress warning about insecure password.
146145
// CONSIDER: Intercepting stdout and stderr and converting to colorized
147146
// console output with `$this->info` and `->error`.
148147
passthru(
149-
static::mysqlCommandPrefix($db_config)
148+
'bash -c "'
149+
. static::mysqlCommandPrefix($db_config)
150150
. ' --result-file=' . escapeshellarg($schema_sql_path)
151151
. ' --no-data'
152-
. ' --routines',
152+
. ' --routines'
153+
. ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"',
153154
$exit_code
154155
);
155156

@@ -170,13 +171,15 @@ private static function mysqlSchemaDump(array $db_config, string $schema_sql_pat
170171

171172
// Include migration rows to avoid unnecessary reruns conflicting.
172173
exec(
173-
static::mysqlCommandPrefix($db_config)
174+
'bash -c "'
175+
. static::mysqlCommandPrefix($db_config)
174176
. ' ' . ($db_config['prefix'] ?? '') . 'migrations'
175177
. ' --no-create-info'
176178
. ' --skip-extended-insert'
177179
. ' --skip-routines'
178180
. ' --single-transaction'
179-
. ' --compact',
181+
. ' --compact'
182+
. ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"',
180183
$output,
181184
$exit_code
182185
);
@@ -207,11 +210,13 @@ private static function mysqlSchemaDump(array $db_config, string $schema_sql_pat
207210
private static function mysqlDataDump(array $db_config, string $data_sql_path) : int
208211
{
209212
passthru(
210-
static::mysqlCommandPrefix($db_config)
213+
'bash -c "'
214+
. static::mysqlCommandPrefix($db_config)
211215
. ' --result-file=' . escapeshellarg($data_sql_path)
212216
. ' --no-create-info --skip-routines --skip-triggers'
213217
. ' --ignore-table=' . escapeshellarg($db_config['database'] . '.' . ($db_config['prefix'] ?? '') . 'migrations')
214-
. ' --single-transaction', // Avoid disruptive locks.
218+
. ' --single-transaction' // Avoid disruptive locks.
219+
. ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"',
215220
$exit_code
216221
);
217222

src/Commands/MigrateLoadCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ private static function mysqlLoad(string $path, array $db_config, int $verbosity
118118
// CONSIDER: Making input file an option which can override default.
119119
// CONSIDER: Avoiding shell specifics like `cat` and piping using
120120
// `file_get_contents` or similar.
121-
$command = 'cat ' . escapeshellarg($path)
121+
$command = 'bash -c "'
122+
. 'cat ' . escapeshellarg($path)
122123
. ' | mysql --no-beep'
123124
. ' --host=' . escapeshellarg($db_config['host'])
124125
. ' --port=' . escapeshellarg($db_config['port'] ?? 3306)
125126
. ' --user=' . escapeshellarg($db_config['username'])
126127
. ' --password=' . escapeshellarg($db_config['password'])
127-
. ' --database=' . escapeshellarg($db_config['database']);
128+
. ' --database=' . escapeshellarg($db_config['database'])
129+
. ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"';
128130
switch($verbosity) {
129131
case OutputInterface::VERBOSITY_QUIET:
130132
$command .= ' -q';

0 commit comments

Comments
 (0)