Community Documentation

Migrating from CPG Dragonfly CMS

Last updated November 19, 2007. Created by webchick on July 2, 2006.
Edited by AjK. Log in to edit this page.

Note: heavy editing in progress

Migrating from CMS Dragonfly CMS consists of two parts: first, migrating the forums using the phpBB2Drupal module (which migrates the users, profiles, forums, forum posts and replies, private messages, and polls) and second, migrating everything else (the articles, categories, roles...).

Migrating the forums

  1. Install Drupal and the following modules:
  2. Enable all of the above modules, plus:
    • Forum
    • Poll
    • Profile
  3. Create a BBCode input format, and set as the default:
    1. Go to administer >> input formats (4.7.x) or Administer >> Site Configuration >> Input Formats (5.x).
    2. Click Add input format, and enter the following options:
      • Name: BBCode
      • Roles: anonymous user, authenticated user
      • Filters: BBCode
    3. Click Save.
    4. Back at the main input formats screen, click the radio next to BBCode and press Set default format.
  4. Apply the DragonflyCMS patch to phpBB2Drupal module.
  5. Configure the php2Drupal migration:
    1. Click administer >> phpBB to Drupal (4.7.x) or Administer >> X >> phpBB to Drupal (5.x)
    2. Click Configure the migration
    3. Enter the following settings:
      • Test on copy first > checked
      • Input format settings > Input format: BBCode
      • Location of phpBB2 data > phpBB2 table prefix: cms_bb
      • Misc settings > Convert Registration Date: checked
      • Polls import: Import polls? checked
      • Private Messages > Import private messages? checked
    4. Click Save configuration
  6. Make sure you have a backup of your database, and then click Execute the migration from the main phpBB2Drupal screen.
  7. Execute each step of the migration by clicking the Import button. Each step will import separate data from phpBB.

Migrating everything else

Below is the beginning of a script to handle migration from CPG Dragonfly CMS 9.0.6.1 to Drupal 4.7. I'll post updates as I get more completed in the coming weeks.

IGNORE the rest of this page for now!!

<?php
// $Id$

/**
* @file
* Handles data import from CPG Dragonfly CMS 9.0.6.1 to Drupal 4.7. Or will someday,
* when I get it finished. :P For now it only handles user and profile fields.
*
* To use:
* 1. Save this script as "dragonfly2drupal.php" in the root of your Drupal installation.
* 2. Change the DRAGONFLY_PREFIX variable if needed -- defaults to 'cms_'
* 3. In your settings.php file, change the $db_url as follows:
*
* BEFORE:
* $db_url = 'mysql://user:pass@host/drupal_db';
*
* AFTER:
* $db_url['default'] = 'mysql://user:pass@host/drupal_db';
* $db_url['dragonfly'] = 'mysql://user:pass@host/dragonfly_db';
*
*/

include_once "includes/bootstrap.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

/** Dragonfly CMS table prefix **/
define('DRAGONFLY_PREFIX', 'cms_');

echo
'<h2>Importing users...</h2>';
dragonfly_user_import();
echo
'<h2>Done.</h2>';

echo
'<h2>Adding profile fields...</h2>';
dragonfly_add_profile_fields();
echo
'<h2>Done.</h2>';

echo
'<h2>Importing profile fields...</h2>';
dragonfly_user_profile_import();
echo
'<h2>Done.</h2>';

echo
'<h2>Importing topics...</h2>';
dragonfly_import_topics();
echo
'<h2>Done.</h2>';

echo
'<h2>Importing blogs...</h2>';
dragonfly_import_blogs();
echo
'<h2>Done.</h2>';

/* FUNCTION DECLARATIONS */

function dragonfly_user_import() {

 
// Drupal => Dragonfly field mappings
 
$user_fields = array(
   
'uid' => 'user_id',
   
'name' => 'username',
   
'pass' => 'user_password',
   
'mail' => 'user_email',
   
'created' => 'user_regdate',
   
'access' => 'user_lastvisit',
   
'login' => 'user_session_time',
   
'status' => 'user_level',
   
'init' => 'user_email',
  );

 
// Retrieve all user records from Dragonfly except anonymous user (#1)
 
db_set_active('dragonfly');
 
$dragonfly_users = db_query('SELECT * FROM %susers WHERE user_id != 1 ORDER BY user_id', DRAGONFLY_PREFIX);

 
// Back to Drupal; handle any data conversion and then import the user info
 
db_set_active('default');
  while (
$user = db_fetch_object($dragonfly_users)) {
   
// Convert registered time
   
$user->user_regdate = strtotime($user->user_regdate);

   
// Set all users but blocked users to active
   
if ($user->user_level != 0) {
     
$user->user_level = 1;
    }

   
// TODO: user avatar handling
    // Dragonfly lets you choose from a pre-existing avatar in the gallery,
    // upload a picture to the site, or link to an external image -- these
    // all need to go under files/pictures/picture-XX.png|jpg|gif, where XX
    // is the user's uid.

    // TODO: signature handling
    // The tricky part here is that Dragonfly's signatures are in BBCode,
    // which Drupal can't parse natively.

    // TODO: Handle blocked users

    // Generate SQL string
   
$sql = drupal_generate_sql_string('users', $user, $user_fields);
   
db_query($sql);

  }

 
// Increase sequence in sequences table
 
$uid = db_result(db_query("SELECT MAX(uid) FROM {users}"));
 
$sql = "UPDATE {sequences} SET id = $uid WHERE name = 'users_uid'";
 
db_query($sql);
}

function
dragonfly_add_profile_fields() {
 
// Real name
 
$profile_values = array(
   
'title' => t('Real Name'),
   
'name' => 'profile_real_name',
   
'category' => t('Profile Information'),
   
'type' => 'textfield',
   
'visibility' => 1,
   
'weight' => -4,
  );
 
profile_field_form_submit(NULL, $profile_values);

 
// Home Page
 
$profile_values = array(
   
'title' => t('Website'),
   
'name' => 'profile_website',
   
'category' => t('Profile Information'),
   
'type' => 'textfield',
   
'visibility' => 2,
   
'weight' => -2,
  );
 
profile_field_form_submit(NULL, $profile_values);

 
// TODO: My Location - use Location/Gmap module for this?

  // My Occupation
 
$profile_values = array(
   
'title' => t('My Occupation'),
   
'name' => 'profile_occupation',
   
'category' => t('Profile Information'),
   
'type' => 'textfield',
   
'visibility' => 2,
   
'weight' => 0,
  );
 
profile_field_form_submit(NULL, $profile_values);

 
// My Interests
 
$profile_values = array(
   
'title' => t('My Interests'),
   
'name' => 'profile_interests',
   
'category' => t('Profile Information'),
   
'type' => 'textfield',
   
'visibility' => 2,
   
'weight' => 2,
  );
 
profile_field_form_submit(NULL, $profile_values);

 
// Bio
 
$profile_values = array(
   
'title' => t('Bio'),
   
'name' => 'profile_bio',
   
'category' => t('Profile Information'),
   
'type' => 'textarea',
   
'visibility' => 2,
   
'weight' => 4,
  );
 
profile_field_form_submit(NULL, $profile_values);
}

function
dragonfly_user_profile_import() {
 
$profile_fields = array(
   
'name' => 'profile_real_name',
   
'user_website' => 'profile_website',
   
'user_occ' => 'profile_occupation',
   
'user_interests' => 'profile_interests',
   
'bio' => 'profile_bio',
  );

 
// Get field IDs for the various profile fields
 
$fids = array();
  foreach (
$profile_fields as $key => $value) {
   
$fids[$key] = db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '$value'"));
  }

 
// Retrieve profile fields from Dragonfly
 
$fields = implode(', ', array_keys($profile_fields));
 
db_set_active('dragonfly');
 
$result = db_query("SELECT user_id, $fields FROM %susers ORDER BY user_id", DRAGONFLY_PREFIX);

 
// Import data
 
db_set_active('default');
  while (
$user = db_fetch_array($result)) {
   
$uid = $user['user_id'];
    foreach (
$user as $key => $value) {
      if (!empty(
$value) && $key != 'user_id') {
       
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $fids[$key], $uid, $value);
      }
    }
  }
}

// Taxonomy
function dragonfly_import_topics() {
 
$vocabulary = array(
   
'name' => t('Topic'),
   
'nodes' => array('story'),
  );
 
//taxonomy_save_vocabulary($topic);
  // Get vocabulary ID
  //$vocabulary['vid'] = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", db_prefix_tables('{vocabulary}_vid')));

  // Grab all topics
 
db_set_active('dragonfly');
 
$result = db_query("SELECT * FROM %stopics ORDER BY topicid", DRAGONFLY_PREFIX);
 
$terms = array();
  while (
$topic = db_fetch_array($result)) {
   
$terms[] = array(
     
'tid' => $topic['topicid'],
     
//'vid' => $vocabulary['vid'],
     
'name' => $topic['topictext'],
    );
  }
 
db_set_active();

 
// Write XML file
  // Note: This line messes up codefilter -- change to ? > without a space.
 
$xml = '<?xml version="1.0" standalone="no"? >' . "\n";
 
$xml .= '<!DOCTYPE taxonomy SYSTEM "taxonomy.dtd">' . "\n";
 
$xml .= "<vocabulary>\n";
  foreach (
$vocabulary as $key => $value) {
    if (
is_array($value)) {
     
$xml .= "  <$key>" . check_plain(implode(',', $value)) . "</$key>\n";
    } else {
     
$xml .= "  <$key>" . check_plain($value) . "</$key>\n";
    }
  }
  foreach (
$terms as $term) {
   
$xml .= "  <term>\n";
    foreach (
$term as $key => $value) {
     
$xml .= "    <$key>" . check_plain($value) . "</$key>\n";
    }
   
$xml .= "  </term>\n";
  }
 
$xml .= "</vocabulary>\n";

 
taxonomy_xml_parse($xml);
 
 
// TODO: images
}

function
dragonfly_import_blogs() {
 
db_set_active('dragonfly');
 
$result = db_query("SELECT * FROM %sblogs", DRAGONFLY_PREFIX);
 
db_set_active();

  while (
$post = db_fetch_object($result)) {
   
$blog = new stdClass();
   
$blog->type = 'blog';
   
$blog->title = $post->title;
   
$blog->body = $post->text;
   
$blog->teaser = node_teaser($post->text);
   
$blog->uid = drupal_get_user_id($post->aid);
   
$blog->status = 1;
   
$blog->created = $post->timestamp;
   
$blog->changed = $post->timestamp;
   
$blog->comment = 2;
   
node_save($blog);
  }
}

function
drupal_get_user_id($username) {
  return
db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $username));
}

function
drupal_generate_sql_string($table, $object, $mapping) {
 
$fields = array();
 
$values = array();
  foreach (
$mapping as $key => $value) {
   
$fields[] = $key;
   
$values[] = $object->$value;
  }
 
$fields = implode(', ', $fields);
 
$values = implode("', '", $values);

  return
"INSERT INTO {$table} ($fields) VALUES ('$values')";
}
?>

Comments

A couple of issues

First, thank you so much for producing this script. We recent developments over at dragonflycms it may mean that more people will be needing it.

I just tried this today (December 30, 2006) with drupal 4.7.4 and dragonfly 9.0.6.1 and found a couple of issues.
First, in the comments about how to get started, there is a minor typo. It is currently as follows:


* AFTER:
* $db_url['default'] = 'mysql://user:pass@host/drupal_db';
* $db_url['dragonfly] = 'mysql://user:pass@host/dragonfly_db';

But there should be a " ' " after "dragonfly" as follows:


* AFTER:
* $db_url['default'] = 'mysql://user:pass@host/drupal_db';
* $db_url['dragonfly'] = 'mysql://user:pass@host/dragonfly_db';

Also, part way through the process I get the following error which I have not been able to address. (Not knowing php is my problem.)

Importing users...
Done.
Adding profile fields...

Fatal error: Call to undefined function: profile_field_form_submit() in /home/myfolder/public_html/mysub/dragonfly2drupal.php on line 115

Hope someone can help me on this one. Thanks.

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x

Installation guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here