Since installing version 1.1 I get the following on both manual and cron synchronization:
Fatal error: __clone method called on non-object in /home/chelmsf/public_html/includes/common.inc on line 1385

Probably connected with this, Advanced User emailed me to say that a new user with a blank name had joined:
"A new user () has just registered on"

Drupal's log says this when cron runs:
Duplicate entry '' for key 2 query: INSERT INTO users (uid, created) VALUES (401, 1202126702) in /home/chelmsf/public_html/includes/database.mysql.inc on line 172.

My highest user is uid 396.

Is the difference between last night's quick hack, and version 1.1 trying to create a user?

CommentFileSizeAuthor
#13 civimember_roles_permission_fix_2.patch6.19 KBAnonymous (not verified)
#5 civimember_roles_uf_id_fix_2.patch4.27 KBAnonymous (not verified)

Comments

Anonymous’s picture

Assigned: Unassigned »

The module doesn't ever try to create a user directly, although one of the API calls I make could be trying to. I will exam the code to see what that clone method is trying to do and see how it relates to the module, but my first impression is this is a problem unrelated to the update. In fact, the update just mirrored the changes you were already running. I would try to get the UID of that blank named user you are talking about and examine your users table to see if that turns up any hints.

I'll let you know if I find anything.

Anonymous’s picture

Ah, sorry. I didn't read your post closely enough. I went through the code again today and found that the user_multiple_role_edit() function can try to create users at one point. There is a lot of code in that function and I haven't finished going through it yet. This may have to do with the way I obtain the UID to pass it to user_multiple_role_edit(). I run this query:

SELECT uid FROM {users} WHERE mail = "CiviCRM Member's Primary Email Goes Here"

If that query is somehow generating a bogus UID and then passing it to user_multiple_role_edit() then that could be creating the problem you are having. I have just recently learned about some CiviCRM API functions that can get the UID for me. I am going to look into those functions today and see if I can fit them into my code. I'll try to get a patch out as soon as possible.

In the mean time, if you wanted to try and isolate which email could be causing the error, then you can run this query on your CiviCRM database (using phpMyAdmin or a shell if you have access to one):

SELECT email FROM civicrm_membership cm
LEFT JOIN civicrm_contact cc ON cm.contact_id = cc.id 
LEFT JOIN civicrm_location cl ON cc.id = cl.entity_id 
LEFT JOIN civicrm_email ce ON cl.id = ce.location_id 
WHERE contact_type = 'Individual' 
AND entity_table = 'civicrm_contact' 
AND cl.is_primary = 1 
AND ce.is_primary = 1
AND membership_type_id = %1
AND cc.domain_id = %2
AND status_id = %3

Where %1 is your membership type id (can be found in civicrm_membership_type table), %2 is equal to your domain id (which is 1 if you are not running in a multi-site environment), and %3 is equal to your status rule id that means current (can be found in civicrm_membership_status). For the status rule ids, you may have to add some OR statements if you are using more than one status rule id that means current. You can then take those e-mails and pass them to the first query I posted and see if you get a UID of 401 (I would use some sort of script to do that unless you only have a handful of emails). If you do, that's the problem. I know that is a lot of work, but it is just a suggestion. Waiting for the patch is probably a lot easier...

Anonymous’s picture

Erg, I just realized that my above post is a dumb suggestion. Just add this code somewhere between lines 419 and 421 in civimember_roles.module:

      echo "<p>";
      echo "UID: " . $uid . " Email: " . $dao->email;
      echo "</p>";

It will do the same thing as my above post in much less time. Look for "UID: 401 Email: Whatever" and that should confirm that this is the problem. Do this on an offline copy of your site if you have one, because this could give users of your site other users info!

rallycivic’s picture

I do get a lot of email addresses from that query!

The highest uid in the Drupal users table is 396.

I tried
SELECT mail FROM users WHERE uid = 401 just in case, but there isn't one.

I also looked at civicrm_contacts: there is an id 401 in there, but he is not a member in CiviCRM, and does not have a Drupal account, so I don't think that is involved.

What about cases where there are more than one email address for contact?

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new4.27 KB

Only the primary CiviCRM Contact E-mail is used to match a Drupal user because I was under the impression that this is how CiviCRM related Drupal users to contacts. From what I've read I still believe that is true, but I think there might be more complexity involved that I'm not taking into account.

I just got some feedback on the CiviCRM developer forums which has led me to create this patch. Remove any custom lines from your civimember_roles.module file (or just restore a fresh copy from the tar archive) and apply the attached patch. Let me know if this fixes your problem and if so I'll schedule the patch to be included in the next release.

EDIT: The patch I posted 8 min ago might cause a problem that I just caught. Use this new one called "civimember_roles_uf_id_fix_2.patch".

rallycivic’s picture

I have checked that I have the patched version on my server: civimember_roles.module,v 1.1.2.4

The __clone method error occurs when I click manual sync, and this appears in the log:

Location http://chelmsfordmc.co.uk/admin/settings/civimember_roles/manual_sync
Referrer http://chelmsfordmc.co.uk/admin/settings/civimember_roles/manual_sync
Message Duplicate entry '' for key 2 query: INSERT INTO users (uid, created, access) VALUES (404, 1202163268, 1202163268) in /home/chelmsf/public_html/includes/database.mysql.inc on line 172.

And the previous time I clicked it produced a similar message with uid 403. With me leaving cron on for a bit, it might have counted up to this from 396 (still the highest user id, and one that signed up this morning) since I first installed 1.1 this morning.

Anonymous’s picture

I'm going to e-mail the Drupal development mailing list to see if I can get any feedback. I have a feeling this is a problem with the Drupal user_save() function. If I can't get any answers there, then I will just write my own role insertion function and see if that helps. I'm hesitant to go that route though, because I feel that the Drupal API is a lot safer.

I found this post discussing similar errors, but it is for Drupal 4.6. It might shed some light on your problem though:

http://drupal.org/node/70106

Anonymous’s picture

Oh, could you also try to download the latest dev snapshot for 1.x? It has a much cleaner application of the patch I posted earlier in it. I made that patch very quickly and it's very hack-ish. I think you will probably get the same error, but it is worth a shot.

Anonymous’s picture

I just thought of this:

Maybe you have duplicate contacts in CiviCRM that are causing this issue. A while back I ran into a situation where CiviCRM had duplicate contacts in the database and actually forced two Drupal users to have the same e-mail. This caused all sorts of problems, but I fixed it by using the remove duplicates tool in the Administer CiviCRM area and deleting the duplicate Drupal users. Probably isn't the exact same situation for you, but could be related.

rallycivic’s picture

The latest dev release - civimember_roles.module,v 1.1.2.5 - works differently. No error messages, but it only syncs user 1.

There will be cases two civimembers share the same email address (some people do when they are living together), but there are no Drupal users with duplicate email addresses. I'll look for CiviCRM duplicates.

Anonymous’s picture

Just got a reponse from the mailing list. It seems this problem could be related to permissions. Can you use the manual sync as user 1? (if you have access to user 1). I think this really could be the issue since you are saying that only user 1 is synced.

I will need to restructure the code so as to give normal users temporary user 1 status to apply the roles. I will probably submit these changes either tonight or tomorrow morning. I just need to take the time to make sure this is done securely, because if done improperly there is a risk of permission escalation.

rallycivic’s picture

Sounds scary!

I am doing the manual sync as user 1 (it is the account I use all the time).

I don't think that is the problem. It synced all the users when I did the simple hack with a "break;" before.

Anonymous’s picture

StatusFileSize
new6.19 KB

I had more time than I thought I would this morning, so here is a patch that performs the user switching. I tested it with both user 1 and another non-privileged user and both tests worked. I also tested cron when logged out and it also worked. This patch is for the unmodified civimember_roles.module file that you can get in the 1.1 tar archive. I am using security suggestions from other developers on the mailing list, so it should be safe.

Hmm, where did you add the break statement before? I thought you just commented out the if statement that was checking to see if the $uid query wasn't FALSE, which was causing problems when you didn't have a Drupal user for a contact.

EDIT: Made a quick change to the patch. Use the file called civimember_roles_permission_fix_2.patch if you downloaded the old one.

rallycivic’s picture

Sorry, I put a "continue;" under the commented-out bit. I did try a break first as I hadn't thought about it enough...

I'll try the patch now.

rallycivic’s picture

That works great! Sorry I doubted it :)

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

That's great news!

You don't have to apologize; I wasn't entirely sure it would solve your issues either. I'm reviewing all the code in the module and will put out another release soon.

Then we can move onto your next future issue and turn that into a release too... =).

Anonymous’s picture

Status: Reviewed & tested by the community » Closed (fixed)