Migrating vBulletin Forum Structure with vbulletin_forum.inc

Last updated on
30 April 2025

With vBulletin Roles and Users in D7, we can now create a class to import the Forum structure...threads and posts to follow

Note: my vbulletinforum.inc uses for_forum_migration reference in the database connection

    Database::addConnectionInfo('for_forum_migration', 'default', array(
      'driver' => 'mysql',
      'database' => 'mysite_vBulletindatabase',
      'username' => 'mysite_d7user',
      'password' => 'd7userpassword',
      'host' => 'localhost',
      'prefix' => 'vb_',
    ));

// vBulletinBoardMigration will behave exactly like the Migration class

class vBulletinBoardMigration extends Migration {

  private $addedContainers = array();

  private $deletedContainers = array();

  public function __construct() {
    parent::__construct();

// Describe the class for the Migrate UI and set the default language to English

    $this->description = t('Migrate the vBulletin board structure');

    $this->defaultLanguage = 'en';

// Specify any dependencies on other classes to ensure that they are migrated before this one



// Specify the source forum table with vb_ prefix from above and identify source fields ordered by an ascending parentid field 

    $query = Database::getConnection('default', 'for_migrate_vbulletin')
      ->select('forum', 'b')
      ->fields('b', array(
        'forumid', 
        'styleid', 
        'title', 
        'title_clean', 
        'description', 
        'description_clean', 
        'options', 
        'displayorder', 
        'replycount', 
        'lastpost', 
        'lastposter', 
        'lastthread', 
        'lastthreadid', 
        'lasticonid', 
        'threadcount', 
        'daysprune', 
        'newpostemail', 
        'newthreademail', 
        'parentid', 
        'parentlist', 
        'password', 
        'link', 
        'childlist', 
        'lastpostid', 
        'showprivate', 
        'defaultsortfield', 
        'defaultsortorder', 
        'vbseo_moderaterefbacks', 
        'vbseo_moderatepingbacks', 
        'vbseo_moderatetrackbacks', 
        'lastprefixid', 
        'imageprefix'
        ))

    ->orderBy('parentid', 'ASC');

// Use the constructed query to create a MigrateSourceSQL and save it in the vBulletinBoardMigration object

    $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE));

// Specify that we want to create taxonomy terms from the source data and put them in forums vocabulary

    $this->destination = new MigrateDestinationTerm('forums');

// Remember what source record created each destination object and track migration status and allow rollback with MigrateSQLMap class 

    $this->map = new MigrateSQLMap(
      $this->machineName,
      array(
        'forumid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'description' => 'vBulletin board structure',
          'alias' => 'b',
        ),
      ),
      MigrateDestinationTerm::getKeySchema()
    );

// For each source row define data mappings to the destination field from the source field

    $this->addFieldMapping('name', 'title');

    $this->addFieldMapping('parent', 'parentid')
         ->sourceMigration($this->machineName);

    $this->addFieldMapping('parent_name');

    $this->addFieldMapping('weight', 'displayorder');

    $this->addFieldMapping('pathauto')
         ->defaultValue('1')
         ->description('OK to pathauto with so few board containers');

// Unmapped destination fields

    $this->addFieldMapping('description') ->description(t('No descriptions in vBulletin to import'))
           ->issueGroup(t('DNM'));
    $this->addFieldMapping('path') ->description(t('Path will be set by Drupals URL alias Forum Paths Pattern for forums and forum containers'))
           ->issueGroup(t('DNM'));
    $this->addFieldMapping('format') ->description(t('Format already set as an argument with description fieldmapping'))
           ->issueGroup(t('DNM'));

  } // close the public function construct

// Create containers from terms that have no parent 0

  public function complete($entity, stdClass $row) {
    if (!$entity->parent || !$entity->parent[0]) {
      $this->addedContainers[] = $entity->tid;
    }
  } // close the public function complete

  public function postImport() {
    $containers = variable_get('forum_containers', array());
    foreach ($this->addedContainers as $container) {
      if (!in_array($container, $containers)) {
        $containers[] = $container;
      }
    }
    variable_set('forum_containers', $containers);

  }  // close the public function postImport

  public function completeRollback($entity_id) {
    $this->deletedContainers[] = $entity_id;
  }

  public function postRollback() {
    $containers = variable_get('forum_containers', array());
    $remaining = array();
    foreach ($containers as $container) {
      if (!in_array($container, $this->deletedContainers) && !in_array($container, $remaining)) {
        $remaining[] = $container;
      }
    }
    variable_set('forum_containers', $remaining);

  }  // close the public function postRollback

}

Help improve this page

Page status: Not set

You can: