Skip to content

Commit

Permalink
Use --defaults-extra-file instead of -p
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Stark committed Sep 24, 2021
1 parent ce1e533 commit 8d5ff8f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions bin/craft-copy-import-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 8d5ff8f

Please sign in to comment.