Add bulk groups with a new module I want to do (in Drupal commons version 6.25) some kind of bulk OG-Management.

On How to programmatically assign/add new groups to the OG in Drupal Commons 6.25, Fuzzy76 says:


  Doing this through PhpMyAdmin will probably be very cumbersome. You would need to add records to node, revisions, any CCK-tables (if your group nodes have CCK fields), og, og_uid (for group memberships) as a minimum. For addding content to your groups, you would need to add to node, revisions (CCK-tables if necessary) and og_ancestry.
  
  It is a bit easier creating a group programmatically:

$groupnode = new stdClass();
$groupnode-&gt;type = 'gruppe'; // Group node type
$groupnode-&gt;status = 1;
$groupnode-&gt;uid = $owner_uid;
$groupnode-&gt;title = $title;
$groupnode-&gt;body = $body;
$groupnode-&gt;og_selective = $group_acces_level;
$groupnode-&gt;og_register = OG_REGISTRATION_NEVER;
$groupnode-&gt;og_directory = OG_DIRECTORY_CHOOSE_FALSE;
$groupnode-&gt;og_private = variable_get('og_private_groups', OG_PRIVATE_GROUPS_CHOOSE_FALSE);
$groupnode-&gt;{_integration_cGroupType}[0]['value'] = $cGroupType_content; // CCK field

node_save($groupnode);

if ($groupnode-&gt;nid) {
  og_insert_group($groupnode);

  // Set space (if spaces_og is used)
  //$ogspace = spaces_load('og', $groupnode-&gt;nid, TRUE);
  //$ogspace-&gt;controllers-&gt;variable-&gt;set('spaces_preset_og', $spacepreset);

  og_save_subscription($groupnode-&gt;nid, $owner_uid, array('is_active' =&gt; 1, 'is_admin' =&gt; 1));
} else {
  dpm('OG creation failed :(');
}



Can anybody help me to port over the code (above) to a module?
If you have a naming pattern for the groups, you could use the Automatic Nodetitles module or the Automatic Entity Label module to give the groups a default name and use the Devel module to generate the groups.

Also since groups are nodes, you could use one of those node import modules to bulk upload the groups from an excel sheet.