public function MigrateExampleMediaNodeMigration::__construct in Migrate Extras 7.2
General initialization of a Migration object.
Overrides Migration::__construct
File
- migrate_extras_examples/
migrate_extras_media/ migrate_extras_media.migrate.inc, line 130 - Examples and test fodder for migration of Media entities and fields.
Class
- MigrateExampleMediaNodeMigration
- Migration class for nodes with media fields.
Code
public function __construct() {
parent::__construct();
$this->description = t('Example migration into the Media module');
$this->dependencies = array(
'MigrateExampleMediaImage',
'MigrateExampleMediaVideo',
);
$this->map = new MigrateSQLMap($this->machineName, array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Media ID',
),
), MigrateDestinationNode::getKeySchema());
// Source fields available in the XML file.
$fields = array(
'id' => t('Source id'),
'title' => t('Title'),
'body' => t('Description'),
'video_uri' => t('A YouTube URI'),
'video_description' => t('Description for a YouTube video'),
'image_filename' => t('Image filename'),
'image_description' => t('Image description'),
'document_filename' => t('Document filename'),
);
// Our test data is in an XML file
$xml_folder = drupal_get_path('module', 'migrate_extras_media');
$items_url = $xml_folder . '/migrate_extras_media.xml';
$item_xpath = '/source_data/item';
$item_ID_xpath = 'id';
$items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
$this->source = new MigrateSourceMultiItems($items_class, $fields);
$this->destination = new MigrateDestinationNode('migrate_extras_media_example');
// Basic fields
$this
->addFieldMapping('title', 'title')
->xpath('title');
$this
->addFieldMapping('uid')
->defaultValue(1);
$this
->addFieldMapping('body', 'body')
->xpath('body');
$this
->addFieldMapping('body:format')
->defaultValue('filtered_html');
// The image and Youtube media entities are imported via their own
// migrations above, we just need to link the fields to them. We do this
// by mapping the primary keys of those migrations (URL and filename) to
// the primary field values, and specifying a file_class of MigrateFileFid.
$this
->addFieldMapping('field_youtube_video', 'video_uri')
->xpath('video/uri')
->sourceMigration('MigrateExampleMediaVideo');
$this
->addFieldMapping('field_youtube_video:file_class')
->defaultValue('MigrateFileFid');
$this
->addFieldMapping('field_media_image', 'image_filename')
->xpath('image/filename')
->sourceMigration('MigrateExampleMediaImage');
$this
->addFieldMapping('field_media_image:file_class')
->defaultValue('MigrateFileFid');
// We have not created a separate migration for documents, we're using the
// file field handler to get those. This works just like it does for regular
// file fields.
$this
->addFieldMapping('field_document', 'document_filename')
->xpath('document/filename');
// This isn't technically necessary - MigrateFileUri is the default
$this
->addFieldMapping('field_document:file_class')
->defaultValue('MigrateFileUri');
$this
->addFieldMapping('field_document:source_dir')
->defaultValue(drupal_get_path('module', 'migrate_extras_media') . '/source_files');
$this
->addFieldMapping('field_document:destination_file', 'document_filename')
->xpath('document/filename');
// Unmapped destination fields
$this
->addUnmigratedDestinations(array(
'is_new',
'status',
'promote',
'revision',
'language',
'sticky',
'created',
'changed',
'revision_uid',
'log',
'tnid',
'body:summary',
'body:language',
'comment',
));
$this
->addUnmigratedDestinations(array(
'field_media_image:language',
'field_media_image:display',
'field_media_image:description',
'field_youtube_video:language',
'field_youtube_video:description',
'field_youtube_video:display',
'field_document:language',
'field_document:destination_dir',
'field_document:file_replace',
'field_document:preserve_files',
'field_document:description',
'field_document:display',
));
if (module_exists('path')) {
$this
->addUnmigratedDestinations(array(
'path',
));
if (module_exists('pathauto')) {
$this
->addUnmigratedDestinations(array(
'pathauto',
));
}
}
$this
->addUnmigratedSources(array(
'image_description',
'video_description',
));
}