Problem/Motivation
Site was upgraded to Drupal 9 and most Drupal and CiviCRM functions seem to be working. I can manually create Drupal accounts that are matched to new contacts in CiviCRM, but the module doesn't work.
Steps to reproduce
Run a Manual Synchronization :
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/batch?id=17425&op=do_nojs&op=do
StatusText: 500 Service unavailable (with message)
ResponseText: The website encountered an unexpected error. Please try again later.Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxx.civicrm_uf_match' doesn't exist: SELECT "uf"."contact_id" AS "contact_id"
FROM
"civicrm_uf_match" "uf"
LEFT OUTER JOIN "civicrm_membership" "m" ON uf.contact_id = m.contact_id
WHERE ("m"."id" IS NOT NULL) AND ("m"."membership_type_id" IN (:db_condition_placeholder_0)); Array
(
[:db_condition_placeholder_0] => 2
)
in Drupal\civicrm_member_roles\CivicrmMemberRoles->getSyncContactIds() (line 184 of modules/contrib/civicrm_member_roles/src/CivicrmMemberRoles.php).
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | civicrm_member_roles_3270435_separate_database.patch | 1.39 KB | seamus_lee |
Issue fork civicrm_member_roles-3270435
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
edsel commentedI encountered the same issue. To fix, I navigated to http://sitename.com/civicrm/admin/setting/uf?reset=1 and copied the entire array for the $databases and pasted it into my settings.php. According to the docs, Drupal 9 should recognize the CiviCRM database automatically as long as you have the correct prefixes, but it seems this module doesn't support that yet and needs this deprecated method.
Comment #3
nickdjmThe original site referred to is using a separate DB for CiviCRM information. I believe this is the root of the issue.
When we look at the logs (including the error message posted) it is always using the Drupal database "name_of_drupal_db.civicrm_uf_match" instead of "name_of_civicrm_db.civicrm_uf_match".
Comment #4
jonhalle commentedThis is because the code uses a database call instead of API. It can be fixed by changing the function getSyncContactIds in src/CivicrmMemberRoles.php. Sorry I don't know how to do a proper pull request:
With this fix there is no need to maintain the database array in settings.php (which used to be required for Views etc but is no longer needed in D9)
Comment #5
seamus_lee commentedI have attached a patch that I worked on for a client site that had this same problem, It is slightly different in that I stuck with using the database but I instantised 2 database arrays as per civicrm entity which provides d9 views integration and modified the database query appropriately. That being said I think with the API or database way it is a bit of 6 of 1 half a dozen of the other, I'll let the maintainers decide which way they want to go.
Comment #8
olivierh65 commentedIn created a PR to implement corrections proposed by jonhalle.
I've not tested it on 2 databases (one for drupal, an another for civicrm).
Comment #9
nubeli commentedComment #10
nubeli commented@seamus_lee your patch gives this error: "Class "Drupal\civicrm_member_roles\Database" not found". Need to add
use Drupal\Core\Database\Database;I think.Comment #11
nubeli commentedThe MR https://git.drupalcode.org/project/civicrm_member_roles/-/merge_requests/2 works for me. The code looks good to me.
Comment #15
sadashiv commentedReleased in 8.x-1.0-beta3
Comment #16
sadashiv commentedMarking this as fixed