Last updated 12 August 2010. Created on 12 August 2010.
Edited by scarer. Log in to edit this page.

I just entered this on a page. Depending on what content type you've created for a group you'll have to change the community node type. This was quite quickly put together. I just turned on the php input filter and created a new page and inserted the script. I received a blank screen but all the data seemed to copy across ok.

 * Description: This script enters all the civicrm groups into Drupal and the organic groups tables.
 * This script was written to help map pre-entered data from civicrm that cannot be synched through 
 * the og groups to civicrm groups module.
 * Author: scarer
 * Date: 12-08-2010
 $titles = array();
 $timestamp = strtotime("now");
 $result = db_query("SELECT title from {civicrm_group}");
 while($rows = db_fetch_object($result)) 
  $cur_title = $rows->title;
  //call function to save to node table
  $nid = savetonode($cur_title, $timestamp);
  //call function to save to node_revisions table
  savetonoderevisions($nid, $cur_title, $timestamp);
  //call function to save to og table
  savetoog($nid, $cur_title);
  //call function to save to og_uid table
  savetooguid($nid, $timestamp);
 //This function saves the group to the Drupal node table
 function savetonode($cur_title, $timestamp)
    //stores the group nid
    $groupnid = '';
    //get nid value of last node and increment it by 1 to insert group node
    $result = db_query("SELECT nid FROM {node} ORDER BY nid DESC LIMIT 1");
     while($rows = db_fetch_object($result)) 
        $groupnid = $rows->nid + 2;
    //insert group node into node table
    db_query("INSERT INTO {node} (vid, type, language, title, uid, status, created, changed, 
    comment, promote, moderate, sticky, tnid, translate) VALUES ($groupnid, 'community', 'en', 
    '$cur_title', 1, 1, $timestamp, $timestamp, 2, 1, 0, 0, 0, 0)");
    //Return groupnid value for use in other functions
    return $groupnid;
  //This function saves the group to the Drupal node revisions table
 function savetonoderevisions($nid, $cur_title, $timestamp)
    db_query("INSERT INTO {node_revisions} (nid, vid, uid, title, timestamp, format) VALUES ($nid, 
    $nid, 1, '$cur_title', $timestamp, 1)");
 //This function saves the group to the Drupal og table
 function savetoog($nid, $cur_title)
     db_query("INSERT INTO {og} (nid, og_selective, og_description, og_theme, og_register, 
     og_directory, og_private) VALUES ($nid, 0, '$cur_title', NULL, 1, 1, 0)");
 //This function saves the group to the Drupal og table
 function savetooguid($nid, $timestamp)
      db_query("INSERT INTO {og_uid} (nid, og_role, is_active, is_admin, uid, created, changed) VALUES ($nid, 
      0, 1, 1, 1, $timestamp, $timestamp)");

Looking for support? Visit the forums, or join #drupal-support in IRC.