diff --git a/src/Joomlatools/Console/Command/Database/AbstractDatabase.php b/src/Joomlatools/Console/Command/Database/AbstractDatabase.php index aa93437..76f01a0 100644 --- a/src/Joomlatools/Console/Command/Database/AbstractDatabase.php +++ b/src/Joomlatools/Console/Command/Database/AbstractDatabase.php @@ -10,7 +10,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; - use Joomlatools\Console\Command\Site\AbstractSite; abstract class AbstractDatabase extends AbstractSite @@ -148,17 +147,21 @@ private function _executeMysqlWithCredentials(callable $callback) $file = tmpfile(); $path = stream_get_meta_data($file)['uri']; + $user = $this->processString($this->mysql->user); + $password = $this->processString($this->mysql->password); + $host = $this->processString($this->mysql->host); + $port = $this->processString($this->mysql->port); + $contents = <<mysql->user} -password={$this->mysql->password} -host={$this->mysql->host} -port={$this->mysql->port} +user={$user} +password={$password} +host={$host} +port={$port} STR; fwrite($file, $contents); - return exec($callback($path)); } finally { @@ -185,4 +188,20 @@ protected function _promptDatabaseDetails(InputInterface $input, OutputInterface $input->setOption('mysql-database', $this->target_db); $input->setOption('mysql-driver', $this->mysql->driver); } + + private function processString(string $input): string + { + // Undo escaped characters + $input = stripslashes($input); + + // Check if the string starts and ends with single quotes and replace with double quotes + // or add double quotes if the string does not start and end with quotes + if (preg_match("/^'(.*)'$/", $input, $matches)) { + $input = '"' . $matches[1] . '"'; + } elseif (!preg_match('/^["\'].*["\']$/', $input)) { + $input = '"' . $input . '"'; + } + + return $input; + } }