From d94e9570c707beb01ffe0ee1783558b30d6c4e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 30 Mar 2014 10:06:39 +0800 Subject: [PATCH 1/2] MDL-44862 always add dbport to dbsocket in pg driver This should hopefully resolve problems when using sockets connection to pg servers running on non-standard ports. --- lib/dml/pgsql_native_moodle_database.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index 64dcc24a5c3..b2a31429a5d 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -135,6 +135,10 @@ class pgsql_native_moodle_database extends moodle_database { $connection = "user='$this->dbuser' password='$pass' dbname='$this->dbname'"; if (strpos($this->dboptions['dbsocket'], '/') !== false) { $connection = $connection." host='".$this->dboptions['dbsocket']."'"; + if (!empty($this->dboptions['dbport'])) { + // Somehow non-standard port is important for sockets - see MDL-44862. + $connection = $connection." port ='".$this->dboptions['dbport']."'"; + } } } else { $this->dboptions['dbsocket'] = ''; From 106f3e9ce9d049e5630722ff5c2bda7b27dc87be Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 30 Mar 2014 22:32:25 +0200 Subject: [PATCH 2/2] MDL-44862 postgres: tests to support socket & port Both the database auth and enrol plugins use ADOdb to perform connections. Socket and port are allowed there if passed as "socket:port", so, when both are configured in CFG, we pass them that way. Else ADOdb defaults to standard port (5432). --- auth/db/tests/db_test.php | 6 +++++- enrol/database/tests/sync_test.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/auth/db/tests/db_test.php b/auth/db/tests/db_test.php index 97a1ecae540..4ef8dbf5fb1 100644 --- a/auth/db/tests/db_test.php +++ b/auth/db/tests/db_test.php @@ -81,7 +81,11 @@ class auth_db_testcase extends advanced_testcase { set_config('sybasequoting', '0', 'auth/db'); if (!empty($CFG->dboptions['dbsocket']) and ($CFG->dbhost === 'localhost' or $CFG->dbhost === '127.0.0.1')) { if (strpos($CFG->dboptions['dbsocket'], '/') !== false) { - set_config('host', $CFG->dboptions['dbsocket'], 'auth/db'); + $socket = $CFG->dboptions['dbsocket']; + if (!empty($CFG->dboptions['dbport'])) { + $socket .= ':' . $CFG->dboptions['dbport']; + } + set_config('host', $socket, 'auth/db'); } else { set_config('host', '', 'auth/db'); } diff --git a/enrol/database/tests/sync_test.php b/enrol/database/tests/sync_test.php index e46d1b1af9b..e831bf3f402 100644 --- a/enrol/database/tests/sync_test.php +++ b/enrol/database/tests/sync_test.php @@ -82,7 +82,11 @@ class enrol_database_testcase extends advanced_testcase { set_config('dbsybasequoting', '0', 'enrol_database'); if (!empty($CFG->dboptions['dbsocket']) and ($CFG->dbhost === 'localhost' or $CFG->dbhost === '127.0.0.1')) { if (strpos($CFG->dboptions['dbsocket'], '/') !== false) { - set_config('dbhost', $CFG->dboptions['dbsocket'], 'enrol_database'); + $socket = $CFG->dboptions['dbsocket']; + if (!empty($CFG->dboptions['dbport'])) { + $socket .= ':' . $CFG->dboptions['dbport']; + } + set_config('dbhost', $socket, 'enrol_database'); } else { set_config('dbhost', '', 'enrol_database'); }