I've created a feature request here: http://drupal.org/node/1417554

But here i'm asking for tips how to implement this feature myself. Here's my feature request:

Our site needs to migrate several (many) existing groups from external websites to our Drupal / OG site.

So far With DRUSH we can automatically:
create users, passwords, assign roles, and send login notification.

But I don't know how to assign multiple users to a group.

I'm new to drupal, but i'd be happy for any type of solution.

What i was thinking of was:

  • commandline with Drush. independant work has been started, but is non-functional, and i did not receive any response at http://drupal.org/node/1090438. I wrote specific questions and notes about this patch on that page.
  • direct DB insert - i don't know where to look, an di just started reading the API. I tried diff'ing a DB before & after a user joins, but it doesn't seem the right way.
  • suggestion: import a list of users (thru text box of file upload

Where to start implementing?
Where's the OG database documented?

Comments

steffenr’s picture

Adding a user to a group or to multiple ground can be done with the help of the og_group function.
In Drupal 7 you just need the group ID and the User-Entity - a short example should explain:

  $gid = 123; // your group ID
  $values['entity'] = user_load($uid); // load a user entity
  $values['entity type'] = 'user';
  $values['state'] = OG_STATE_PENDING; // set membership type
  og_group($gid, $values);

For more information: http://drupalcontrib.org/api/drupal/contributions!og!og.module/function/...

In Drupal 6 you have to use the og_subscribe_user() function:

  $gid = 123; // your group ID
  $user_obj = user_load($uid); // load a user object
  og_subscribe_user($gid, $user_obj);

For more information: http://drupalcontrib.org/api/drupal/contributions!og!og.module/function/...

SteffenR

alibama’s picture

views bulk operations or this patch for feeds may help http://drupal.org/node/857424

rar’s picture

This worked to add all users to the first group created.

<?php 

$result = db_query('SELECT u.uid from {users} u where status= 1');
$gid = 1; //group entityID != gid
foreach ($result as $record) { 
  echo "USER = ",$record->uid;
  $values['entity'] = user_load($record->uid);
  $values['entity type'] = 'user';
  $values['state'] = OG_STATE_ACTIVE;
  og_group($gid,$values);
}

?>

The API documentation states that function og_group() takes 3 arguments, but the API documentation does not match the actual code in the module.