Views integration error on D9

Created on 12 February 2021, almost 4 years ago
Updated 9 May 2024, 7 months ago

Problem/Motivation

I have a Drupal9 site with CiviCRM 5.34. Drupal9 and CiviCRM has separate databases, none of them has table prefixes. For accessing these two databases I use the same MySQL DB user, this DB user has ALL PRIVILEGES on both databases. Drupal) and CiviCRM works fine, has no problem to access the databases.

Steps to reproduce

After installing CiviCRM Entity, I copied the integration code for the settings.php or settings.local.php from the "Views Integration settings" as shown on civicrm/admin/setting/uf?reset=1. After clearing all caches, I created a simple View, but if I try to test it, I got the following error message: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'XxXDBUserXxX'@'localhost' for table 'civicrm_contact': SELECT "civicrm_contact"."id" AS "id", DATE_FORMAT((civicrm_contact.modified_date + INTERVAL 3600 SECOND), '%Y%m%d') AS "civicrm_contact_modified_date_day", 'civicrm_last_mod:default' AS "view_name" FROM {civicrm_contact} "civicrm_contact" ORDER BY "civicrm_contact_modified_date_day" DESC LIMIT 11 OFFSET 0; Array ( ) .

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary pal_ur

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom davej

    @markusa I may have tracked down one scenario where civicrm_entity doesn't assign the correct prefix to a Civi table. This was happening on a custom field set table called civicrm_value_confidentiality__data_protection_6 . I suspect the problem may be this code in src/Plugin/views/query/CivicrmSql.php , function query() :

          // If the table is not prefixed with civicrm_, assume it is a Drupal table
          // and convert it to a fully qualified table name. But, make sure it has
          // not already been converted.
          // Also do not convert any drupal custom fields.
          if ((strpos($table['table'], 'civicrm_') !== 0 && strpos($table['table'], '.') === FALSE) || (strpos($table['table'], 'civicrm_') === 0 && strpos($table['table'], '__') !== FALSE)) {
             $table['table'] = $connection->getFullQualifiedTableName($table['table']);
          }
    

    I.e. if the table name contains a double underscore, then regard it as already fully qualified?

  • πŸ‡ΊπŸ‡ΈUnited States markusa

    @davej

    Ok, yep, I think we need to enhance that logic. Double underscore was a way we tried to assume a table is a Drupal table.

  • πŸ‡ΊπŸ‡ΈUnited States markusa

    Here's a PR for the 8.x-3.x branch, which is what you are using for Drupal 9
    https://github.com/eileenmcnaughton/civicrm_entity/pull/432
    https://patch-diff.githubusercontent.com/raw/eileenmcnaughton/civicrm_en...

    Please let me know if this fixes the issue for you, and if so, I'll get it merged.

  • πŸ‡¬πŸ‡§United Kingdom davej

    Hi @markusa,

    I've given that a quick test on a view which previously failed on civicrm_value tables with a double underscore and the fix looks successful there. I haven't given it comprehensive testing to see if it breaks anything else but it looks good on that specific issue and the change to the logic seems reasonable. Looks like you're having to take into account a case where a table name begins with civicrm_ but will be found in the Drupal db, which does ring a bell - some Civi-related modules' tables, maybe?

    Thanks!

    Dave

  • πŸ‡ΊπŸ‡ΈUnited States markusa

    Ok great, if it fixes your error, that's what I need to know.
    I'm testing the other scenarios we tested when originally making these updates. So far so good.

    Likely to get merged soon and in next release sometime in June.

  • πŸ‡ΊπŸ‡ΈUnited States markusa

    Pushed this out to a release, in 8.x-3.5 and 4.0.0-alpha4

  • πŸ‡¬πŸ‡§United Kingdom davej

    Hi Mark,

    Wow, that was quick! Open source at its best. Thank you.

    Dave

  • πŸ‡¬πŸ‡§United Kingdom chumkui

    I have had a similar issue that was only solved when I gave the civicrm database user SELECT rights on the Drupal database - I have documented it here . The documentation does not mention this step, hence the question.

  • Status changed to Fixed 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States markusa
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024