CLI Database for docker

This commit is contained in:
Roman 2022-02-21 15:54:37 +01:00
parent 872ef4099a
commit fb0c7a55cf

20
cli.php

@ -42,9 +42,11 @@ function getDatabaseConfig(): ConnectionData {
$config = new Configuration(); $config = new Configuration();
$database = $config->getDatabase(); $database = $config->getDatabase();
if ($database !== null && $database->getProperty("isDocker", false) && !is_file("/.dockerenv")) { if ($database !== null && $database->getProperty("isDocker", false) && !is_file("/.dockerenv")) {
if (count($argv) < 2 || $argv[1] !== "db") {
$command = array_merge(["docker", "exec", "-it", "php", "php"], $argv); $command = array_merge(["docker", "exec", "-it", "php", "php"], $argv);
$proc = proc_open($command, [1 => STDOUT, 2 => STDERR], $pipes, "/application"); $proc = proc_open($command, [1 => STDOUT, 2 => STDERR], $pipes, "/application");
exit(proc_close($proc)); exit(proc_close($proc));
}
} }
function getUser(): ?User { function getUser(): ?User {
@ -104,13 +106,13 @@ function handleDatabase(array $argv) {
} else if ($action === "export" || $action === "import") { } else if ($action === "export" || $action === "import") {
// database config // database config
$config = getDatabaseConfig(); $dbConfig = getDatabaseConfig();
$dbType = $config->getProperty("type") ?? null; $dbType = $dbConfig->getProperty("type") ?? null;
$user = $config->getLogin(); $user = $dbConfig->getLogin();
$password = $config->getPassword(); $password = $dbConfig->getPassword();
$database = $config->getProperty("database"); $database = $dbConfig->getProperty("database");
$host = $config->getHost(); $host = $dbConfig->getHost();
$port = $config->getPort(); $port = $dbConfig->getPort();
// subprocess config // subprocess config
$env = []; $env = [];
@ -170,6 +172,10 @@ function handleDatabase(array $argv) {
} }
$command = array_merge([$command_bin], $command_args); $command = array_merge([$command_bin], $command_args);
if ($dbConfig->getProperty("isDocker", false)) {
$command = array_merge(["docker", "exec", "-it", "db"], $command);
}
$process = proc_open($command, $descriptorSpec, $pipes, null, $env); $process = proc_open($command, $descriptorSpec, $pipes, null, $env);
if (is_resource($process)) { if (is_resource($process)) {