1

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->type = 'gruppe'; // Group node type
$groupnode->status = 1;
$groupnode->uid = $owner_uid;
$groupnode->title = $title;
$groupnode->body = $body;
$groupnode->og_selective = $group_acces_level;
$groupnode->og_register = OG_REGISTRATION_NEVER;
$groupnode->og_directory = OG_DIRECTORY_CHOOSE_FALSE;
$groupnode->og_private = variable_get('og_private_groups', OG_PRIVATE_GROUPS_CHOOSE_FALSE);
$groupnode->{_integration_cGroupType}[0]['value'] = $cGroupType_content; // CCK field

node_save($groupnode);

if ($groupnode->nid) {
  og_insert_group($groupnode);

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

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

Can anybody help me to port over the code (above) to a module?

  • 1
    I think this question is quite broad as you don't specify in which event you want to create the groups: You could create them when a new user registers, when a new node is created, or once. Depending on that, the hook to implement is different. – kiamlaluno Mar 29 '12 at 15:10
  • i want to create new groups on the fly. i run a drupal commons and i need to have a ready-setup of 2500 groups. New users should be able to register to those - allready-setup groups. question: can i create the groups via phpmyadmin or do i need a module like the above mentioned either the one from fuzzy or the og_manage. What do you advice? i would love to see a solution - or do i have to do it via phpmyadmin? – zero Mar 29 '12 at 17:10
  • Any body who likes to help out here!? – zero Mar 30 '12 at 15:46
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.