Download & Extend

Mass creation of groups

Project:Organic groups
Version:6.x-2.x-dev
Component:og.module
Category:support request
Priority:major
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Does anyone know of a module or anything else that can facilitate the mass creation of groups. For instance if I had a text based list of towns and I wanted to create a group for each town how would I go about it?

Comments

#1

Status:active» fixed

Look up migration modules, such as Node Import, Node Export, or Feeds. (Feeds can process CSV files into nodes handily)

#2

Also as another option (since I recently did this). Drupal 6/7 have drupal_execute() for D6 and drupal_form_submit() for D7. If you install OG group and create a content type for your groups -- you can then programmatically submit the form via a Drush script or a module update using core drupal functions.

An example of inspecting, and how to understand a POST of node creation form and also using drupal_form_submit() can be found here, and some nifty Firebug usage:
http://lionide.wordpress.com/2010/12/06/drupal-7-programatically-create-...

As an example the php script I created and then ran via "drush php-script" was as follows to create about a dozen groups on-the-fly in D7:

<?php
# Eg filename "make-groups.php"
# run via "drush -l {SITENAME_URI} php-script make-groups.php


# include this if you run this within a module to assure the node_form() functions
# have been included for the code you're about to run ...
module_load_include('inc', 'node', 'node.pages');

  # groups to create.
  $areas = array(
      'group1',
      'group2',
      'group3',
      'group4',
      'group5',
      'group6',
      'group7',
      'group8',
      'group9',
      'group10',
      'group11',
      'group12',
  );


  foreach ($areas as $area) {
    $form_state = array();
    # these are essentially cookie-cutter fields shared by most any node type.
    $form_state['values']['body']['und'][0]['format'] = 2;
    $form_state['values']['body']['und'][0]['summary'] = '';
    $form_state['values']['body']['und'][0]['value'] = '';
    $form_state['values']['book']['bid'] = 0;
    $form_state['values']['book']['plid'] = -1;
    $form_state['values']['book']['weight'] = 0;
    $form_state['values']['changed'] = '';
    $form_state['values']['date'] = '';
    $form_state['values']['log'] = '';
    $form_state['values']['op'] = t('Save');
    $form_state['values']['path']['alias'] = '';
    $form_state['values']['revision'] = 1;
    $form_state['values']['status'] = 1;
    $form_state['values']['language'] = LANGUAGE_NONE;

    # these are the 2 fields that we actually care about for groups.
    $form_state['values']['title'] = $area;
    $form_state['values']['group_group']['und'] = 1;

    $newNode = new stdClass();
    # the machine name of the OG group you created.
    $newNode->type = "idgroup";
    $newNode->language= LANGUAGE_NONE;
    $newNode->options = array();
    $newNode->uid = 1;
    $newNode->promote = 0;
    $newNode->module = 'node';
    node_object_prepare($newNode);

    # Call your content type's node create form passing a canned $form_state
    # and a bare-bones node object.
    drupal_form_submit('idgroup_node_form', $form_state, $newNode);
  }

#3

deleted by author.

#4

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here