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

(dev/core#1926) MySQL SSL - Fixes for Backdrop, Drupal 7, Standalone #31912

Merged
merged 2 commits into from
Jan 31, 2025
Merged
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
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B. This variable ($ufDSN) is only used for two things: DB::connect($ufDSN) and new Exception("Cannot connect...$ufDSN...").

The error message may look slightly different, but it's not a meaningful difference.

What is meaningful is that DB::connect() is replaced by CRM_Utils_SQL::connect(), which behaves more reliably.


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 @@ -596,8 +596,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