How to programmatically assign/add new groups to the OG in Drupal Commons 6.25 How to programmatically add new groups to Organic Groups in Drupal Commons 6.25?  I have to do that for approximately 3000 groups. A preliminary test cycle that generates 50 will be the first step.

Which methods are preferable?


http://drupal.org/project/og_massadd
http://drupal.org/node/54979
http://drupal.org/node/1433036
http://drupal.org/project/devel 


By the way, the images are stored in sites/default/files/imagecache/group_images_medium/group_images.

Questions that arise


Are the images, and the corresponding paths referenced in the database somewhere?
How can I do the mass-upload of the image and besides that, the mass-creation of groups?
Which tables of the tables of OG are necessary?
Is it enough to take the "og" table itself?


PS: An ongoing attempt with comments for Drupal 6 can be seen here: http://drupal.org/node/79874.
I am the author of og_massadd (which is quite buggy as it is now, unfortunately), but that module is only for adding users to an OG. But if I understand you correctly, you want to create the actual organic groups?

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 :(');
}