Skip to content

Commit

Permalink
Merge pull request #31912 from totten/mysql-ssl-dbconnect
Browse files Browse the repository at this point in the history
(dev/core#1926) MySQL SSL - Fixes for Backdrop, Drupal 7, Standalone
  • Loading branch information
seamuslee001 authored Jan 31, 2025
2 parents a207a31 + f8717af commit 08bee84
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 1 addition & 3 deletions CRM/Utils/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,8 @@ public static function runSqlQuery($dsn, $queryString, $prefix = NULL, $dieOnErr
}
else {
require_once 'DB.php';
$dsn = CRM_Utils_SQL::autoSwitchDSN($dsn);
try {
$options = CRM_Utils_SQL::isSSLDSN($dsn) ? ['ssl' => TRUE] : [];
$db = DB::connect($dsn, $options);
$db = CRM_Utils_SQL::connect($dsn);
}
catch (Exception $e) {
throw new CRM_Core_Exception("Cannot open $dsn: " . $e->getMessage());
Expand Down
6 changes: 6 additions & 0 deletions CRM/Utils/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public static function getDatabaseVersion() {
return CRM_Core_DAO::singleValueQuery('SELECT VERSION()');
}

public static function connect($dsn) {
$dsn = CRM_Utils_SQL::autoSwitchDSN($dsn);
$options = CRM_Utils_SQL::isSSLDSN($dsn) ? ['ssl' => TRUE] : [];
return DB::connect($dsn, $options);
}

/**
* Does the DSN indicate the connection should use ssl.
*
Expand Down
4 changes: 2 additions & 2 deletions CRM/Utils/System/Backdrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ protected function getUsersTableName() {
public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
$config = CRM_Core_Config::singleton();

$ufDSN = CRM_Utils_SQL::autoSwitchDSN($config->userFrameworkDSN);
$ufDSN = $config->userFrameworkDSN;
try {
$dbBackdrop = DB::connect($ufDSN);
$dbBackdrop = CRM_Utils_SQL::connect($ufDSN);
}
catch (Exception $e) {
throw new CRM_Core_Exception("Cannot connect to Backdrop database via $ufDSN, " . $e->getMessage());
Expand Down
5 changes: 3 additions & 2 deletions CRM/Utils/System/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realP

$config = CRM_Core_Config::singleton();

$ufDSN = CRM_Utils_SQL::autoSwitchDSN($config->userFrameworkDSN);
$ufDSN = $config->userFrameworkDSN;

try {
$dbDrupal = DB::connect($ufDSN);
$dbDrupal = CRM_Utils_SQL::connect($ufDSN);
}
catch (Exception $e) {
throw new CRM_Core_Exception("Cannot connect to drupal db via $ufDSN, " . $e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion ext/standaloneusers/Civi/Standalone/SessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function gc($max_lifetime): int {
* @return bool
*/
public function open($path, $name): bool {
$this->db = DB::connect(\CRM_Core_Config::singleton()->dsn);
$this->db = \CRM_Utils_SQL::connect(\CRM_Core_Config::singleton()->dsn);
$this->db->autoCommit(FALSE);

return TRUE;
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ public static function toBeSkipped_getSqlOperators() {
// Re:^^^ => the failure was probably correct behavior, and test is now fixed, but yeah 5.5 is deprecated, and don't care enough to verify.
// Test data providers should be able to run in pre-boot environment, so we connect directly to SQL server.
require_once 'DB.php';
$dsn = CRM_Utils_SQL::autoSwitchDSN(CIVICRM_DSN);
$db = DB::connect($dsn);
$db = CRM_Utils_SQL::connect(CIVICRM_DSN);
if ($db->connection instanceof mysqli && $db->connection->server_version < 50600) {
$entitiesWithout[] = 'Dedupe';
}
Expand Down

0 comments on commit 08bee84

Please sign in to comment.