Skip to content

Commit 71fff03

Browse files
joshtrichardsskjnldsv
authored andcommitted
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>
1 parent f4f7c75 commit 71fff03

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

core/Command/Db/ConvertType.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ protected function readPassword(InputInterface $input, OutputInterface $output)
142142
if ($input->isInteractive()) {
143143
/** @var QuestionHelper $helper */
144144
$helper = $this->getHelper('question');
145-
$question = new Question('What is the database password?');
145+
$question = new Question('What is the database password (press <enter> for none)? ');
146146
$question->setHidden(true);
147147
$question->setHiddenFallback(false);
148148
$password = $helper->ask($input, $output, $question);
149+
if ($password === null) {
150+
$password = ''; // possibly unnecessary
151+
}
149152
$input->setOption('password', $password);
150153
return;
151154
}
@@ -233,9 +236,24 @@ protected function getToDBConnection(InputInterface $input, OutputInterface $out
233236
'password' => $input->getOption('password'),
234237
'dbname' => $input->getArgument('database'),
235238
]);
239+
240+
// parse port
236241
if ($input->getOption('port')) {
237242
$connectionParams['port'] = $input->getOption('port');
238243
}
244+
245+
// parse hostname for unix socket
246+
if (preg_match('/^(.+)(:(\d+|[^:]+))?$/', $input->getOption('hostname'), $matches)) {
247+
$connectionParams['host'] = $matches[1];
248+
if (isset($matches[3])) {
249+
if (is_numeric($matches[3])) {
250+
$connectionParams['port'] = $matches[3];
251+
} else {
252+
$connectionParams['unix_socket'] = $matches[3];
253+
}
254+
}
255+
}
256+
239257
return $this->connectionFactory->getConnection($type, $connectionParams);
240258
}
241259

0 commit comments

Comments
 (0)