From fb0c7a55cf80ba6f5e70ee5b447ff0147355cc4b Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 21 Feb 2022 15:54:37 +0100 Subject: [PATCH] CLI Database for docker --- cli.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/cli.php b/cli.php index 6004a8c..8ee3347 100644 --- a/cli.php +++ b/cli.php @@ -42,9 +42,11 @@ function getDatabaseConfig(): ConnectionData { $config = new Configuration(); $database = $config->getDatabase(); if ($database !== null && $database->getProperty("isDocker", false) && !is_file("/.dockerenv")) { - $command = array_merge(["docker", "exec", "-it", "php", "php"], $argv); - $proc = proc_open($command, [1 => STDOUT, 2 => STDERR], $pipes, "/application"); - exit(proc_close($proc)); + if (count($argv) < 2 || $argv[1] !== "db") { + $command = array_merge(["docker", "exec", "-it", "php", "php"], $argv); + $proc = proc_open($command, [1 => STDOUT, 2 => STDERR], $pipes, "/application"); + exit(proc_close($proc)); + } } function getUser(): ?User { @@ -104,13 +106,13 @@ function handleDatabase(array $argv) { } else if ($action === "export" || $action === "import") { // database config - $config = getDatabaseConfig(); - $dbType = $config->getProperty("type") ?? null; - $user = $config->getLogin(); - $password = $config->getPassword(); - $database = $config->getProperty("database"); - $host = $config->getHost(); - $port = $config->getPort(); + $dbConfig = getDatabaseConfig(); + $dbType = $dbConfig->getProperty("type") ?? null; + $user = $dbConfig->getLogin(); + $password = $dbConfig->getPassword(); + $database = $dbConfig->getProperty("database"); + $host = $dbConfig->getHost(); + $port = $dbConfig->getPort(); // subprocess config $env = []; @@ -170,6 +172,10 @@ function handleDatabase(array $argv) { } $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); if (is_resource($process)) {