From 6a511829cb6a39216400384fc1b86ecf0b3cd3ad Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 Jun 2017 14:41:39 -0700 Subject: [PATCH 1/3] CRM-20768 - install - Accept mysql port == Background == In previous releases, the web-based installation script allowed you to enter the MySQL "server" with a `host:port` combination (e.g. `127.0.0.1:3307`). I believe this regressed during the mysql=>mysqli transition. == Before == If you use the web-based install UI and enter a `host:port` combination, the error messages indicate a confusing mix of information (e.g. some indicating port 3306, some indicating port 3307). == After == If you use the web-based install UI and enter a `host:port` combination, it uses the specified port. ---------------------------------------- * CRM-20768: Web-based installation should accept non-standard MySQL port https://issues.civicrm.org/jira/browse/CRM-20768 --- install/index.php | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/install/index.php b/install/index.php index ca739c9606ec..f7d9c0bacf31 100644 --- a/install/index.php +++ b/install/index.php @@ -549,6 +549,30 @@ public function checkdatabase($databaseConfig, $dbName) { } } + /** + * Connect via mysqli. + * + * This is exactly the same as mysqli_connect(), except that it accepts + * the port as part of the `$host`. + * + * @param $host + * @param $username + * @param $password + * @param string $database + * @return \mysqli + */ + protected function connect($host, $username, $password, $database = '') { + $hostParts = explode(':', $host); + if (count($hostParts) > 1) { + list ($host, $port) = $hostParts; + } + else { + $port = ''; + } + $conn = @mysqli_connect($host, $username, $password, $database, $port); + return $conn; + } + /** * Check everything except the database. */ @@ -949,7 +973,7 @@ public function requireApacheModule($moduleName, $testDetails) { */ public function requireMysqlConnection($server, $username, $password, $testDetails) { $this->testing($testDetails); - $this->conn = @mysqli_connect($server, $username, $password); + $this->conn = $this->connect($server, $username, $password); if ($this->conn) { return TRUE; @@ -966,7 +990,7 @@ public function requireMysqlConnection($server, $username, $password, $testDetai */ public function requireMySQLServer($server, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, NULL, NULL); + $conn = $this->connect($server, NULL, NULL); if ($conn || mysqli_connect_errno() < 2000) { return TRUE; @@ -1011,7 +1035,7 @@ public function requireMySQLVersion($version, $testDetails) { */ public function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (!$conn) { $testDetails[2] .= ' ' . ts("Could not determine if MySQL has InnoDB support. Assuming no."); $this->error($testDetails); @@ -1046,7 +1070,7 @@ public function requireMySQLInnoDB($server, $username, $password, $database, $te */ public function requireMySQLTempTables($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not login to the database.'); $this->error($testDetails); @@ -1076,7 +1100,7 @@ public function requireMySQLTempTables($server, $username, $password, $database, */ public function requireMySQLTrigger($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not login to the database.'); $this->error($testDetails); @@ -1116,7 +1140,7 @@ public function requireMySQLTrigger($server, $username, $password, $database, $t */ public function requireMySQLLockTables($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not connect to the database server.'); $this->error($testDetails); @@ -1163,7 +1187,7 @@ public function requireMySQLLockTables($server, $username, $password, $database, */ public function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not connect to the database server.'); $this->error($testDetails); @@ -1197,7 +1221,7 @@ public function requireMySQLAutoIncrementIncrementOne($server, $username, $passw */ public function requireMySQLThreadStack($server, $username, $password, $database, $minValueKB, $testDetails) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not connect to the database server.'); $this->error($testDetails); @@ -1241,7 +1265,7 @@ public function requireDatabaseOrCreatePermissions( $onlyRequire = FALSE ) { $this->testing($testDetails); - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); $okay = NULL; if (@mysqli_select_db($conn, $database)) { @@ -1380,7 +1404,7 @@ class Installer extends InstallRequirements { * @param $database */ public function createDatabaseIfNotExists($server, $username, $password, $database) { - $conn = @mysqli_connect($server, $username, $password); + $conn = $this->connect($server, $username, $password); if (@mysqli_select_db($conn, $database)) { // skip if database already present From 8e1997f986835383b4c76ce51a89d00ef7bb8770 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 Jun 2017 17:24:33 -0700 Subject: [PATCH 2/3] CRM-20768 - Install UI - Distinguish host/port in IPv6 --- install/index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install/index.php b/install/index.php index f7d9c0bacf31..1339a10d5f39 100644 --- a/install/index.php +++ b/install/index.php @@ -563,8 +563,9 @@ public function checkdatabase($databaseConfig, $dbName) { */ protected function connect($host, $username, $password, $database = '') { $hostParts = explode(':', $host); - if (count($hostParts) > 1) { - list ($host, $port) = $hostParts; + if (count($hostParts) > 1 && strrpos($host, ']') !== strlen($host) - 1) { + $port = array_pop($hostParts); + $host = implode(':', $hostParts); } else { $port = ''; From 28d4c7189309ce5e7f385cd68c93fe43bd010a37 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 Jun 2017 17:31:14 -0700 Subject: [PATCH 3/3] CRM-20768 - install - Improve docblock --- install/index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install/index.php b/install/index.php index 1339a10d5f39..79010fffb1af 100644 --- a/install/index.php +++ b/install/index.php @@ -555,9 +555,10 @@ public function checkdatabase($databaseConfig, $dbName) { * This is exactly the same as mysqli_connect(), except that it accepts * the port as part of the `$host`. * - * @param $host - * @param $username - * @param $password + * @param string $host + * Ex: 'localhost', 'localhost:3307', '127.0.0.1:3307', '[::1]', '[::1]:3307'. + * @param string $username + * @param string $password * @param string $database * @return \mysqli */