CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Problem adding drupal user from code
Pages: [1]

Author Topic: Problem adding drupal user from code  (Read 1254 times)

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Problem adding drupal user from code
May 02, 2011, 11:19:33 pm
Hi gang,

I'm working on a Drupal multi-site project in which two sites are sharing the same {users} table; this normally works fine by defining $db_prefix['users'] = 'drupal_shared_database.' in settings.php for both sites, so Drupal always knows where to find the users table.

The problem comes up when CiviCRM creates a Drupal user. This happens in CRM_Core_BAO_CMSUser::createDrupalUser(), and actually creating the Drupal user goes just fine, because it uses Drupal methods to do it.  The next step then is to create an entry in civicrm_uf_match, using the new Drupal user uid.  To get that uid, this code doesn't use Drupal methods to access the data, but instead queries the database with its own methods, essentially requiring the `users` table to be in the database defined in $config->userFrameworkDSN, which in this case it's not.

Would it be reasonable to have this Drupal-specific method to use Drupal's db_query() to get the uid? Or is there another way I should be handling this?

Thanks,
- TM
« Last Edit: May 02, 2011, 11:34:50 pm by TwoMice »
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Problem adding drupal user from code
May 03, 2011, 02:00:16 am
Won't setting the cms user table here get around this?

http://sandbox.civicrm.org/en/civicrm/admin/setting/uf?reset=1

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Problem adding drupal user from code
May 03, 2011, 06:26:42 am

I think we can and should make 2 improvements to that part of the code:

1. Use db_query instead of our database queries. Do the same for joomla. the D6 and D7 code will be different.

2. Doing the above, means we can get rid of the users table name and hence one less config option

twomice: wanna take a look and submit a patch? if you do it for drupal, we can convince a joomla developer to do the same for joomla

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Problem adding drupal user from code
May 03, 2011, 08:47:01 am
Yep, Eileen is right. Of course that fixes the problem instantly.

Also, it looks like a patch is pretty simple, will try to submit something today.

Thanks,
-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Problem adding drupal user from code
May 03, 2011, 10:04:00 am
Patches for 3.4 and 4.0 added in this issue:
http://issues.civicrm.org/jira/browse/CRM-8020
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Problem adding drupal user from code

This forum was archived on 2017-11-26.