Migrating vBulletin Posts with vbulletin_forum.inc
Last updated on
30 April 2025
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
With roles, users, forum structure and threads migrated, we can now add posts to the threads with something like...
class vBulletinPostMigration extends Migration {
public function __construct() {
parent::__construct();
$this->description = t('Migrate vBulletin forum posts');
// Set the source table's primary key
$this->map = new MigrateSQLMap(
$this->machineName,
array(
'postid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'vBulletin forum posts',
'alias' => 'p',
),
),
MigrateDestinationNode::getKeySchema(),
'for_forum_migration'
);
// Set the query to get the source object
$query = Database::getConnection('default', 'for_forum_migration')
->select('post', 'p')
->fields('p', array(
'postid',
'threadid',
'parentid',
'username',
'userid',
'title',
'dateline',
'pagetext',
'allowsmilie',
'showsignature',
'ipaddress',
'iconid',
'visible',
'attach',
'infraction',
'reportthreadid',
));
// D7 thread includes the first post as it's body, so join with the post table and do not the first post for each thread
$query->join('thread', 't', 't.threadid = p.threadid AND p.postid != t.firstpostid');
// This sort ensures that post parents are saved before children.
$query->orderBy('dateline', 'ASC');
$count_query = Database::getConnection('default', 'for_forum_migration')
->select('post', 'p');
$count_query->addExpression('COUNT(postid)', 'cnt');
$this->source = new MigrateSourceSQL($query, array(), $count_query, array('map_joinable' => FALSE));
// Define the destination as the D7 comment
$this->destination = new MigrateDestinationComment('comment_node_forum');
// Map fields from vBulletin posts to D7 forum comments
$this->addFieldMapping('nid', 'threadid')
->sourceMigration('vBulletinThread');
$this->addFieldMapping('name', 'username');
$this->addFieldMapping('uid', 'userid')
->sourceMigration('vBulletinUser');
$this->addFieldMapping('thread', 'title')
->sourceMigration('vBulletinThread')
->defaultValue(NULL);
$this->addFieldMapping('subject', 'title')
->defaultValue(NULL);
$this->addFieldMapping('created', 'dateline');
$this->addFieldMapping('changed', 'dateline');
$this->addFieldMapping('status', 'visible');
$this->addFieldMapping('hostname', 'ipaddress');
$this->addFieldMapping('comment_body', 'pagetext');
//Do not map the following source fields
$this->addFieldMapping(NULL, 'allowsmilie') ->description(t('Not a setting per comment in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'showsignature') ->description(t('Set at roles level in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'iconid') ->description(t('Not used in vBulletin or D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'attach') ->description(t('Set at content type level in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'infraction') ->description(t('Not used in vBulleton or D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'reportthreadid') ->description(t('Not used in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'parentid') ->description(t('No parentid as I want thread posts to be linear rather than threaded in D7'))
->issueGroup(t('DNM'));
// Unmapped destination fields
$this->addFieldMapping('pid') ->description(t('Want linear rather than threaded threads so pid not used in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping('mail') ->description(t('No anonymous comments in vBulletin and email set at user level in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping('homepage') ->description(t('No anonymous comments in vBulletin and homepage set at user level in D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping('language') ->description(t('Language set at site level in D7'))
->issueGroup(t('DNM'));
}
// D7 comment subject titles need to be trimmed to a max of 50 characters
public function prepareRow(stdClass $row) {
if (drupal_strlen($row->title) > 50) {
$row->title = drupal_substr($row->subject, 0, 50) . '...';
}
}
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion