Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format of Databasehost for Sockets #35884

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
* Your host server name, for example ``localhost``, ``hostname``,
* ``hostname.example.com``, or the IP address. To specify a port use
* ``hostname:####``; to specify a Unix socket use
* ``/path/to/directory/containing/socket`` e.g. ``/run/postgresql/``.
* ``localhost:/path/to/directory/containing/socket`` e.g. ``localhost:/run/postgresql/``.
*/
'dbhost' => '',

Expand Down
5 changes: 5 additions & 0 deletions lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ protected function splitHostFromPortAndSocket($host): array {
'host' => $host,
];

// Host variable may only be an unix socket.
if ((strpos($host, '/') !== false) and (strpos($host, ':') === false)) {
$host = 'localhost:'.$host;
}

$matches = [];
if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) {
// Host variable carries a port or socket.
Expand Down
10 changes: 9 additions & 1 deletion lib/private/Setup/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ abstract class AbstractDatabase {
/** @var string */
protected $dbName;
/** @var string */
protected $unix_socket;
/** @var string */
protected $dbHost;
/** @var string */
protected $dbPort;
Expand Down Expand Up @@ -114,10 +116,16 @@ protected function connect(array $configOverwrite = []): Connection {
'user' => $this->dbUser,
'password' => $this->dbPassword,
'tablePrefix' => $this->tablePrefix,
'dbname' => $this->dbName
'dbname' => $this->dbName,
'unix_socket' => $this->unix_socket
];

// adding port support through installer
// Host variable may only be an unix socket.
if ((strpos($this->dbHost, '/') !== false) and (strpos($this->dbHost, ':') === false)) {
$this->unix_socket = $this->dbHost;
$this->dbHost = 'localhost:'.$this->dbHost;
}
if (!empty($this->dbPort)) {
if (ctype_digit($this->dbPort)) {
$connectionParams['port'] = $this->dbPort;
Expand Down