This report applies to using the 1342632 dev branch in git (see #1342632: Deprecate OG group entity).

If a module calls user_save() on the currently logged in global $user object, there is a slew of error messages and the user's memberships to any groups are deleted. If the user is not a member of any groups and this happens, there are no errors.

This is using the latest og 1342632 branch and associated entityrelationships 1343854 branch.

Here is the list of errors that shows up:

  • Notice: Trying to get property of non-object in OgBehaviorHandler->load() (line 27 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->load() (line 28 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 97 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->load() (line 27 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->load() (line 28 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 97 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 100 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 108 of/mnt/SDData/web/www/html/.../sites/all/modules/og/plugins/entityreference/behavior/og_behavior.inc).
  • Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in EntityAPIController->load() (line 184 of/mnt/SDData/web/www/html/.../sites/all/modules/entity/includes/entity.controller.inc).

Comments

paul2’s picture

Title: Branch 1342632: Calling user_save() causes user to be kicked out of all OG groups » Branch 1342632: Logging in as user that is a member of any group produces errors on login, and all their memberships are deleted
Priority: Normal » Major

Just going to throw this out there, I may be totally wrong:

Could it have to do with the fact that the field_data_og_group_ref table never gets populated with records when I add users to groups? I've always wondered why that table remains empty no matter how many user-to-group and node-to-group associations I have in the system, even though they are all using the og_group_ref field. In Views, for example, I've tried using og_group_ref to figure out group membership relationships but they never work because that table remains empty. Instead, I've had to rely solely on the og_membership table to determine these associations.

Perhaps during user_save(), the contents of field_data_og_group_ref are getting enumerated, and being that it's totally empty, it assumes that user is not a member of any groups and updates the contents of the og_membership table accordingly? Just a thought...

amitaibu’s picture

Priority: Major » Normal

I can't reproduce that. Have you tried it on a clean installation?

(Let's keep priority normal, as this branch isn't out yet, and is known to be a work in progress).

paul2’s picture

Okay, trying to reproduce it on a fresh install... so far no luck here, either! Will post another update soon as I find anything out.

amitaibu’s picture

Status: Active » Fixed

Ok, closing for now.

paul2’s picture

Priority: Major » Normal
Status: Active » Fixed

To anyone who needs help with this, I think I managed to fix it. I uninstalled OG and entityreference completely (which involves deleting any OG-related fields from all entities), deleted the module directories, inspected the database and removed any leftover remnants of OG and ER that I could find (including tables, field definitions, and whatever else - there were a few bits here and there), cleared the cache, then "git clone"d the OG and ER branches again, re-enabled the modules, and recreated the group properties on my entities. I am no longer getting these weird errors when a non-admin user that is a member of groups logs in.
Edit: this is irrelevant now... see ticket description.

paul2’s picture

Status: Fixed » Active

Actually... I spoke too soon! It is totally still happening - I just hadn't logged in again for a while. Sigh... Narrowing down the problem... will post an update soon!
See issue description.

paul2’s picture

Status: Active » Closed (fixed)

Gosh.. never mind. I finally found the source of the errors. It's a module I've written. Must be written poorly. Really sorry for the hassle, @Amitaibu!
See issue description.

paul2’s picture

Title: Branch 1342632: Logging in as user that is a member of any group produces errors on login, and all their memberships are deleted » Branch 1342632: Calling user_save() causes user to be kicked out of all OG groups
Status: Fixed » Active

I've narrowed down this problem further. I believe my module is written properly. What my module does is very simple. It hooks into hook_user_login(), tweaks one or two fields on the user account that is being logged in (basically syncing some fields from a remote service), then saves the user object using user_save(). In fact, not even changing any fields at all on the account, but simply re-saving the global $user object causes this slew of errors (and the user gets kicked out of all groups they were a member of).

See if it happens for you:

function mymodule_user_login(&$edit, $account) {
  $account = user_save($account, array());
}
paul2’s picture

Issue summary: View changes

Hiding confidential information from summary

amitaibu’s picture

Title: Branch 1342632: Logging in as user that is a member of any group produces errors on login, and all their memberships are deleted » Branch 1342632: Calling user_save() causes user to be kicked out of all OG groups
Status: Closed (fixed) » Postponed (maintainer needs more info)

I can't reproduce.

paul2’s picture

Okay. Well I've just worked around it for now by using direct SQL queries to update user records. When I have more time again I'll try to come up with a comprehensive step-by-step procedure to reproduce this!

therainmakor’s picture

Please see https://drupal.org/node/1226586#comment-7610001 for a possible solution.

therainmakor’s picture

Issue summary: View changes

Making ticket description reflect current behaviour.