Posted by playfulwolf on January 19, 2013 at 4:45pm
Hi,
Have a hard time figuring out how to add user to some OG group automatically on lets say user registration.
The first part is easy, event:
"After saving a new user account"
Condition: none
Action:
"Subscribe user to group"
...and then I am stuck.
For example, my OG group is nid 3.
Any clues?

Comments
Registration will be problematic
Depending upon the type of registration you offer - (without verification, with verification, admin setup etc) rules will not catch all scenarios (my experience anyway).
The only way I have found to automate something like this is to include checks like this in my own custom module where I have other checks and tweeks. I have a predefined log in redirect page that fires off these checks. On this page I have a block that calls scripts to ensure that the user is up to date on what I want them to be. Yes this is overhead, however this gives me automated access to new and existing accounts as well.
Untested query but should work (GID and UID already set):
$og_mem = db_query("SELECT * FROM og_membership WHERE etid = :etid AND gid = :gid", array('etid'=>$uid, 'gid'=>$gid));
$number_of_rows = $og_mem->rowCount();
if($number_of_rows == 0){
$into_group = db_insert('og_membership')
->fields(array('type', 'etid', 'entity_type', 'gid', 'group_type', 'state', 'created', 'field_name', 'language'))
->values(array(
'type' => 'og_membership_type_default',
'etid' => $uid,
'entity_type' => 'user',
'gid' => $gid,
'group_type' => 'node',
'state' => '1',
'created' => REQUEST_TIME,
'field_name' => 'og_user_node',
'language' => 'en',
))->execute();
}
Thak you, I am not going that
Thak you, I am not going that far - simply said, how to add user to group? I have very very little experience with OG and even less with Rules. It is enough for now "After saving a new user account" condition.
drupal+me: jeweler portfolio