fix(occ): Add support for UNIX sockets to db:convert-type

Fixes #31998

Adds support to `occ db:convert-type` to support UNIX socket connections via MySQL/MariaDB. Uses same `dbhost` / `hostname` parameter parsing logic (adapted) as used elsewhere (at least the relevant parts) for consistency.

Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
This commit is contained in:
Josh Richards 2023-07-07 23:59:52 -04:00 committed by skjnldsv
parent f4f7c757d4
commit 71fff03e9b

View file

@ -142,10 +142,13 @@ class ConvertType extends Command implements CompletionAwareInterface {
if ($input->isInteractive()) {
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new Question('What is the database password?');
$question = new Question('What is the database password (press <enter> for none)? ');
$question->setHidden(true);
$question->setHiddenFallback(false);
$password = $helper->ask($input, $output, $question);
if ($password === null) {
$password = ''; // possibly unnecessary
}
$input->setOption('password', $password);
return;
}
@ -233,9 +236,24 @@ class ConvertType extends Command implements CompletionAwareInterface {
'password' => $input->getOption('password'),
'dbname' => $input->getArgument('database'),
]);
// parse port
if ($input->getOption('port')) {
$connectionParams['port'] = $input->getOption('port');
}
// parse hostname for unix socket
if (preg_match('/^(.+)(:(\d+|[^:]+))?$/', $input->getOption('hostname'), $matches)) {
$connectionParams['host'] = $matches[1];
if (isset($matches[3])) {
if (is_numeric($matches[3])) {
$connectionParams['port'] = $matches[3];
} else {
$connectionParams['unix_socket'] = $matches[3];
}
}
}
return $this->connectionFactory->getConnection($type, $connectionParams);
}