Skip to content

Commit

Permalink
Merge pull request #21042 from eileenmcnaughton/uf
Browse files Browse the repository at this point in the history
[REF] Use OO when determining what to suggest for settings.php prefixes for drupal/backdrop views, instead of scattered "if cms =="
  • Loading branch information
eileenmcnaughton authored Sep 14, 2021
2 parents 3a50b67 + 6440c50 commit a20a1f6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
12 changes: 3 additions & 9 deletions CRM/Admin/Form/Setting/UF.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public function buildQuickForm() {
$config->dsn != $config->userFrameworkDSN || !empty($drupal_prefix)
)
) {
$dsn = CRM_Utils_SQL::autoSwitchDSN($config->dsn);
$dsnArray = DB::parseDSN($dsn);

$dsnArray = DB::parseDSN(CRM_Utils_SQL::autoSwitchDSN($config->dsn));
$tableNames = CRM_Core_DAO::getTableNames();
asort($tableNames);
$tablePrefixes = '$databases[\'default\'][\'default\'][\'prefix\']= [';
Expand All @@ -77,13 +77,7 @@ public function buildQuickForm() {
}
// add default prefix: the drupal database prefix
$tablePrefixes .= "\n 'default' => '$drupal_prefix',";
$prefix = "";
if ($config->dsn != $config->userFrameworkDSN) {
$prefix = "`{$dsnArray['database']}`.";
if ($config->userFramework === 'Backdrop') {
$prefix = "{$dsnArray['database']}.";
}
}
$prefix = $config->userSystem->getCRMDatabasePrefix();
foreach ($tableNames as $tableName) {
$tablePrefixes .= "\n '" . str_pad($tableName . "'", 41) . " => '{$prefix}',";
}
Expand Down
12 changes: 12 additions & 0 deletions CRM/Utils/System/Backdrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -1056,4 +1056,16 @@ public function getCMSPermissionsUrlParams() {
return ['ufAccessURL' => url('admin/config/people/permissions')];
}

/**
* Get the CRM database as a 'prefix'.
*
* This returns a string that can be prepended to a query to include a CRM table.
*
* However, this string should contain backticks, or not, in accordance with the
* CMS's drupal views expectations, if any.
*/
public function getCRMDatabasePrefix(): string {
return str_replace(parent::getCRMDatabasePrefix(), '`', '');
}

}
17 changes: 17 additions & 0 deletions CRM/Utils/System/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,23 @@ public function getCMSPermissionsUrlParams() {
return [];
}

/**
* Get the CRM database as a 'prefix'.
*
* This returns a string that can be prepended to a query to include a CRM table.
*
* However, this string should contain backticks, or not, in accordance with the
* CMS's drupal views expectations, if any.
*/
public function getCRMDatabasePrefix(): string {
$crmDatabase = DB::parseDSN(CRM_Core_Config::singleton()->dsn)['database'];
$cmsDatabase = DB::parseDSN(CRM_Core_Config::singleton()->userFrameworkDSN)['database'];
if ($crmDatabase === $cmsDatabase) {
return '';
}
return "`$crmDatabase`.";
}

/**
* Invalidates the cache of dynamic routes and forces a rebuild.
*/
Expand Down

0 comments on commit a20a1f6

Please sign in to comment.