public function BeerUserMigration::__construct in Migrate 6.2
Same name and namespace in other branches
- 7.2 migrate_example/beer.inc \BeerUserMigration::__construct()
General initialization of a Migration object.
Overrides BasicExampleMigration::__construct
File
- migrate_example/
beer.inc, line 178 - A basic example of using the Migrate module to import taxonomy, users, nodes, and comments.
Class
- BeerUserMigration
- And that's it for the BeerTerm migration! For a simple migration, all you have to do is define the source, the destination, and mappings between the two - to import the data you simply do: drush migrate-import BeerTerm
Code
public function __construct() {
// The basic setup is similar to BeerTermMigraiton
parent::__construct();
$this->description = t('Beer Drinkers of the world');
$this->map = new MigrateSQLMap($this->machineName, array(
'aid' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Account ID.',
),
), MigrateDestinationUser::getKeySchema());
$query = db_select('migrate_example_beer_account', 'mea')
->fields('mea', array(
'aid',
'status',
'posted',
'name',
'nickname',
'password',
'mail',
'sex',
'beers',
));
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationUser();
// One good way to organize your mappings is in three groups - mapped fields,
// unmapped source fields, and unmapped destination fields
// Mapped fields
// This is a shortcut you can use when the source and destination field
// names are identical (i.e., the email address field is named 'mail' in
// both the source table and in Drupal).
$this
->addSimpleMappings(array(
'status',
'mail',
));
// Our source table has two entries for 'alice', but we must have a unique
// username in the Drupal 'users' table. dedupe() creates new, unique
// destination values when the source field of that value already exists.
// For example, if we're importing a user with name 'test' and a user
// 'test' already exists in the target, we'll create a new user named
// 'test_1'.
// dedupe() takes the Drupal table and column for determining uniqueness.
$this
->addFieldMapping('name', 'name')
->dedupe('users', 'name');
// The migrate module automatically converts date/time strings to UNIX timestamps.
$this
->addFieldMapping('created', 'posted');
$this
->addFieldMapping('pass', 'password');
// Instead of mapping a source field to a destination field, you can
// hardcode a default value. You can also use both together - if a default
// value is provided in addition to a source field, the default value will
// be applied to any rows where the source field is empty or NULL.
$this
->addFieldMapping('roles')
->defaultValue(DRUPAL_AUTHENTICATED_RID);
// Unmapped source fields
$this
->addFieldMapping(NULL, 'nickname')
->issueGroup(t('DNM'));
// Unmapped destination fields
// This is a shortcut you can use to mark several destination fields as DNM
// at once
$this
->addUnmigratedDestinations(array(
'theme',
'signature',
'access',
'login',
'timezone',
'language',
'picture',
'role_names',
));
// Oops, we made a typo - this should have been 'init'! If you have
// migrate_ui enabled, look at the BeerUser info page - you'll see that it
// displays a warning "int used as destination field in mapping but not in
// list of destination fields", and also lists "1 unmapped" under Destination,
// where it highlights "init" as unmapped.
$this
->addFieldMapping('int')
->issueGroup(t('DNM'));
}