Skip to content

Commit

Permalink
drupal 9 views fix (alternative)
Browse files Browse the repository at this point in the history
I took a look at #20682 and it seemed clear that
in it's current state it would fix one CMS (d9) & break another (d7). This is
an alternate that will hopefully be non-breaky
  • Loading branch information
eileenmcnaughton committed Aug 6, 2021
1 parent e586838 commit ffb2ea5
Show file tree
Hide file tree
Showing 4 changed files with 53 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->getCMSDatabasePrefix();
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 CMS database as a 'prefix'.
*
* This returns a string that can be prepended to a query to include a CMS table.
*
* However, this string should contain backticks, or not, in accordance with the
* CMS's drupal views expectations, if any.
*/
public function getCMSDatabasePrefix(): string {
return str_replace(parent::getCMSDatabasePrefix(), '`', '');
}

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

/**
* Invalidates the cache of dynamic routes and forces a rebuild.
*/
Expand Down
21 changes: 21 additions & 0 deletions CRM/Utils/System/Drupal9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* Drupal specific stuff goes here.
*/
class CRM_Utils_System_Drupal9 extends CRM_Utils_System_Drupal8 {}

0 comments on commit ffb2ea5

Please sign in to comment.