MigrateDestinationTable
Last updated on
30 April 2025
An easy way to simply migrate into a Drupal table (i.e., one defined
through the Schema API) is to use the MigrateDestinationTable destination.
Just pass the table name to getKeySchema and the MigrateDestinationTable constructor and each of the columns in the destination table will become a destination field that you can use with your field mappings.
class WineTableMigration extends AdvancedExampleMigration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = 'Miscellaneous table data';
$this->softDependencies = array('WineComment');
$table_name = 'migrate_example_wine_table_dest';
$this->map = new MigrateSQLMap($this->machineName,
array('fooid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => t('Source ID'),
)
),
MigrateDestinationTable::getKeySchema($table_name)
);
$query = db_select('migrate_example_wine_table_source', 't')
->fields('t', array('fooid', 'field1', 'field2'));
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationTable($table_name);
// Mapped fields
$this->addFieldMapping('drupal_text', 'field1');
$this->addFieldMapping('drupal_int', 'field2');
$this->addUnmigratedDestinations(array('recordid'));
$this->removeFieldMapping('path');
$this->removeFieldMapping('pathauto');
}
}
NOTE: The above code is from the wine.inc file from the migrate example module.
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