Skip to content

Commit c28340d

Browse files
authored
Merge pull request #39242 from joshtrichards/db-convert-type-mysql-socket-no-pw
2 parents e11a8f0 + 71fff03 commit c28340d

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

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)