From 8d5ff8fb34c1c9908e89aaa993ebe35b7be4ace8 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Fri, 24 Sep 2021 13:35:58 +0200 Subject: [PATCH] Use --defaults-extra-file instead of -p --- bin/craft-copy-import-db.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bin/craft-copy-import-db.php b/bin/craft-copy-import-db.php index 27c8818..f87965a 100755 --- a/bin/craft-copy-import-db.php +++ b/bin/craft-copy-import-db.php @@ -47,17 +47,28 @@ exit(1); } +$credentialsFile = "/tmp/mysql-extra.cnf"; +$credentialsFileContent = [ + "[client]", + "user=" . getenv('DB_USER'), + "password=" . getenv('DB_PASSWORD'), + "host=" . getenv('DB_SERVER') +]; + +if (false === file_put_contents($credentialsFile, join(PHP_EOL, $credentialsFileContent))) { + echo "ERROR: unable to write $credentialsFile"; + exit(1); +} -$cmd = 'mysql --force -u {DB_USER} -p{DB_PASSWORD} -h {DB_SERVER} {DB_DATABASE} < {file} && echo 1'; $tokens = [ - '{file}' => $file, - '{DB_USER}' => getenv('DB_USER'), - '{DB_PASSWORD}' => getenv('DB_PASSWORD'), - '{DB_SERVER}' => getenv('DB_SERVER'), + '{FILE}' => $file, + '{EXTRA_FILE}' => $credentialsFile, '{DB_DATABASE}' => getenv('DB_DATABASE'), ]; +$cmd = 'mysql --defaults-extra-file={EXTRA_FILE} --force {DB_DATABASE} < {FILE} && echo 1'; $cmd = str_replace(array_keys($tokens), array_values($tokens), $cmd); + $process = \Symfony\Component\Process\Process::fromShellCommandline($cmd); $process->run();