You are here

public static function Migration::saveFieldMappings in Migrate 7.2

Record an array of field mappings to the database.

Parameters

$machine_name:

array $field_mappings:

1 call to Migration::saveFieldMappings()
Migration::registerMigration in includes/migration.inc
Register a new migration process in the migrate_status table. This will generally be used in two contexts - by the class detection code for static (one instance per class) migrations, and by the module implementing dynamic (parameterized class)…

File

includes/migration.inc, line 314
Defines the base class for import/rollback processes.

Class

Migration
The base class for all import objects. This is where most of the smarts of the migrate module resides. Migrations are created by deriving from this class, and in the constructor (after calling parent::__construct()) initializing at a minimum the name,…

Code

public static function saveFieldMappings($machine_name, array $field_mappings) {

  // Clear existing field mappings
  db_delete('migrate_field_mapping')
    ->condition('machine_name', $machine_name)
    ->execute();
  foreach ($field_mappings as $field_mapping) {
    $destination_field = $field_mapping
      ->getDestinationField();
    $source_field = $field_mapping
      ->getSourceField();
    db_insert('migrate_field_mapping')
      ->fields(array(
      'machine_name' => $machine_name,
      'destination_field' => is_null($destination_field) ? '' : $destination_field,
      'source_field' => is_null($source_field) ? '' : $source_field,
      'options' => serialize($field_mapping),
    ))
      ->execute();
  }
}