don't fiddle with other module's tables - og
moshe weitzman - October 10, 2006 - 19:47
| Project: | userplus |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
hi all. great module.
i happenned to look at the recent diff which added some og integration. good idea! however, the implementation is very dicey. module like userplus should not start inserting into another modules tables like og_uid. that breaks the modularity of drupal. sometimes modules listen for group subscription changes and those won't notice these changes.
far preferable is to setup $user with the new group associations and then call user_save(). you could even try to validate first. this advice is true for any user property changes, not just og.

#1
Moshe - I agree that it would be better to call upon user.module or og.module to save the group associations.
Looking at the og code, in 4.7, hook_user('update', ...) doesn't do anything with group subscriptions. I'd like to either fill up $user->og_groups with the right subscriptions and call user_save() or call upon some helpers in og.module.
og_add_users_submit() loads up a user object for each user that is getting subscribed and then calls og_save_subscription() -- perhaps I should do the same thing for subscriptions that have been added.
Also I'd need to call og_delete_subscription for subscriptions that have been removed -- it would be nice to call og_unsubscribe(), but if it's not possible to unsubscribe one of the users, then drupal_access_denied() gets called, which wouldn't be good in the middle of processing a list of subscriptions.
#2
It sounds like you are trying to progmatically add a subscription. I am doing something similar and calling og_save_subscription() works fine for me.
#3
This is fixed in the new 5.x version. We're calling og_delete_subscription() when a user is unsubscribed, and og_save_subscription() when a user is subscribed via the 'assign user groups' form.
#4