diff options
author | Josh Richards <josh.t.richards@gmail.com> | 2023-07-07 23:59:52 -0400 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-08-16 09:04:36 +0200 |
commit | 71fff03e9bc9e1b1074a6a993d43f041e95c782b (patch) | |
tree | fd0a28cb9150abf9e713d890b4462d7fd3dfdb37 /core | |
parent | f4f7c757d45cdcb8d9dc170249a09bc22cd2a994 (diff) | |
download | nextcloud-server-71fff03e9bc9e1b1074a6a993d43f041e95c782b.tar.gz nextcloud-server-71fff03e9bc9e1b1074a6a993d43f041e95c782b.zip |
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>
Diffstat (limited to 'core')
-rw-r--r-- | core/Command/Db/ConvertType.php | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php index 592285a8309..031d5a83d12 100644 --- a/core/Command/Db/ConvertType.php +++ b/core/Command/Db/ConvertType.php @@ -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); } |