Migrating Blob avatar and profile images
Last updated on
30 April 2025
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
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