Community Documentation

Migrating Blob avatar and profile images

Last updated February 6, 2013. Created by StuartDH on February 6, 2013.
Log in to edit this page.

vBulletin stores the avatar and profile images in 'blob' fields (filedata). The following vbulletin_blob.inc can be used to get them into Drupal

// vBulletinBlobMigration will behave exactly like the Migration class

class vBulletinBlobMigration extends Migration {
  public function __construct() {
    parent::__construct();

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

    $this->description = t('Migrate vBulletin user avatars');

    $this->defaultLanguage = 'en';

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


// Specify the source user table with vb_ prefix from above and identify source fields ordered by ascending userid

    $query = Database::getConnection('default', 'for_migrate_vbulletin')
      ->select('customavatar', 'v')
      ->fields('v', array(
        'userid',
        'filedata',
        'dateline',
        'filename',
        'visible',
        'filesize',
        'width',
        'height',
        'filedata_thumb',
        'width_thumb',
        'height_thumb',
        ));

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

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

// Specify that we want to create files from the blob source data

    $this->destination = new MigrateDestinationFile('file', 'MigrateFileBlob');

// 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(
        'userid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'description' => 'vBulletin Unique user ID',
          'alias' => 'u',
        ),
      ),
      MigrateDestinationFile::getKeySchema()
    );

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

    $this->addFieldMapping('uid', 'userid');

    $this->addFieldMapping('value', 'filedata')
         ->description('An image blob in the DB');

    $this->addFieldMapping('timestamp', 'dateline');

    $this->addFieldMapping('destination_file', 'filename');

    $this->addFieldMapping('destination_dir')
        ->defaultValue('public://avatars');

// Do not map the following destination fields

// Do not map the following source fields
   
    } // close the public function construct

} // close the vBulletinBlobMigration class

About this page

Drupal version
Drupal 7.x
Level
Intermediate

Administration & Security Guide

Drupal’s online documentation is © 2000-2013 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. Comments on documentation pages are used to improve content and then deleted.