1

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?

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.

2

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->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 :(');
}
  • g day dear fuzzy76 - great to hear from you. Interesting and overwehlming advice. Note - i run Drupal commons 6.25 but if you talk about the actual and mean by actual the organic Groups that run in version 7.12 (which might be a bit different from the old version) then i have to say. This advice fits also - since the aquiqa-developer-group is currently workin on the transition of the drupal-commons - from version 6 to 7 . At least as far as i understand the current discussion - any way your ideas are great and i dig deeper during the next days. I come back and report all the findings! – zero Mar 26 '12 at 7:54
  • btw - sorry for being the newby - where to apply this code!? in Drush, commmand-line or where?! Love to hear from you. Thx for an additional hint! – zero Mar 26 '12 at 7:57
  • That depends on what you are trying to accomplish. My usage of this code is in a module functions exposed as a web service for creating groups. In your case, I would think a Drush command would be a good fit. – Fuzzy76 Mar 27 '12 at 7:16
  • hello Fuzzy - many many thanks. That means you have a module, where you can apply the above mentioned code. Great thing. Well i guess that it is pretty difficult to integrate the module into drupal. Can we download the module somewhere!? That would be great! Weill it would be a extraordinary help to the community and in some way an additional thing to the mass-user-stuff, what do you think!? – zero Mar 27 '12 at 15:20
  • That module is just an implementation of a private web service for creating classrooms in our eLearning website (and to complicate things, not all rooms are organic groups), so I'm afraid it's not written for publishing, and probably would not help you any more than the example above. Apart from that, drush.ws/docs/commands.html might help you further along. – Fuzzy76 Mar 28 '12 at 6:43

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.