Skip to content

Commit

Permalink
(occ db:convert-type) Add support for UNIX sockets
Browse files Browse the repository at this point in the history
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 AndyScherzinger committed Feb 27, 2024
1 parent 250084f commit 1ac39e7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/Command/Db/ConvertType.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,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 @@ -254,6 +257,16 @@ protected function getToDBConnection(InputInterface $input, OutputInterface $out
if ($input->getOption('port')) {
$connectionParams['port'] = $input->getOption('port');
}
if (strpos($input->getOption('hostname'), ':') !== false) {
// Host variable may carry a socket (or port)
[$host, $portOrSocket] = explode(':', $input->getOption('hostname'), 2);

Check notice

Code scanning / Psalm

PossiblyUndefinedArrayOffset Note

Possibly undefined array key
if (ctype_digit($portOrSocket)) {
$connectionParams['port'] = $portOrSocket; // to be consistent with how we handle this elsewhere we accept this too but don't document it
} else {
$connectionParams['unix_socket'] = $portOrSocket;
}
$connectionParams['host'] = $host;
}
return $this->connectionFactory->getConnection($type, $connectionParams);
}

Expand Down

0 comments on commit 1ac39e7

Please sign in to comment.