Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
joshtrichards authored and skjnldsv committed Aug 16, 2024
commit 71fff03e9bc9e1b1074a6a993d43f041e95c782b
20 changes: 19 additions & 1 deletion core/Command/Db/ConvertType.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ protected function readPassword(InputInterface $input, OutputInterface $output)
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;
}
Expand Down Expand Up @@ -233,9 +236,24 @@ protected function getToDBConnection(InputInterface $input, OutputInterface $out
'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);
}

Expand Down