background preloader

Migrate

Facebook Twitter

Mappings. Source fields are mapped to destination fields by making calls to $this->addFieldMapping() in your Migration class constructor.

Mappings

Field mappings are represented as instances of the MigrateFieldMapping class, which implements a fluent interface akin to that of the Drupal 7 database API. This enables optional behavior to be attached to mappings, without using a long list of optional arguments on addFieldMapping(). <? Php // Each method returns a FieldMapping object $this->addFieldMapping('sticky') ->description(t('Should we default this to 0 or 1? ')) ->issueGroup(t('Client questions')) ->issueNumber(765736) ->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_LOW);? The following methods can be chained: ->description($description): provide a description for the mapping. Simple mapping In its simplest form, a field mapping defines a straight copy of source data to the destination Drupal object: <?

It's not uncommon for fields to have the same name on both the source and destination sides. <? <? <? <? Handling files in Drupal 7. File classes File classes, implementing the PHP interface MigrateFileInterface, are the key to the file import approach.

Handling files in Drupal 7

A file class represents the logic for taking a particular representation of a file (such as a URL or a database blob) and tying it to a Drupal 7 file entity in the appropriate way. Each file field mapping, or migration to a file destination, will have a file class associated with it, and that file class determines what options and fields are available when mapping it. There are three file classes provided by the Migrate module itself: MigrateFileUri This is the default file class - the one that will be used if you don't specify a file class. It takes the following subfields and options: source_dir - This is, logically, the source directory relative which to interpret the primary value. Destination_dir - This represents the parent path within Drupal to store the file. Destination_file - This is the filename relative to destination_dir at which to store the file.

<? <? <? MigrateDestinationNode. To migrate content into Drupal nodes, use the MigrateDestinationNode class: <?

MigrateDestinationNode

Php$node_options = MigrateDestinationNode::options($language, $text_format);$this->destination = new MigrateDestinationNode('article', $node_options);$this->addFieldMapping('title', 'source_title');$this->addFieldMapping('body', 'source_body');$this->addFieldMapping('body:summary', 'source_teaser');...? > The first argument is the bundle (content type) you wish to migrate source content into. Fields nid - The Drupal node ID. Title - The title of the node. uid - The Drupal user ID of the account that created the node. created - The date and time when the node was created. Changed - The date and time when the node was last modified. Status - The node status, 1 for published and 0 for unpublished. promote - Whether the node is promoted to the front page (1 for promoted, 0 for not promoted). sticky - Whether the node should be listed at the top of listings by default (1 for sticky, 0 for not sticky).

Options Language. Drupal migrate file_exists_reuse.