Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.