public function MigrateExampleMediaVideoMigration::__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 72 - Examples and test fodder for migration of Media entities and fields.
Class
- MigrateExampleMediaVideoMigration
- Migration class for media_youtube entities.
Code
public function __construct() {
parent::__construct();
$this->description = t('Example migration of Youtube videos');
$this->map = new MigrateSQLMap($this->machineName, array(
'uri' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'YouTube URI',
),
), MigrateDestinationMedia::getKeySchema());
// Source fields available in the XML file.
$fields = array(
'uri' => t('URI of a YouTube video'),
'description' => t('Description of the video'),
);
// 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/video';
$item_ID_xpath = 'uri';
$items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
$this->source = new MigrateSourceMultiItems($items_class, $fields);
// In this case, we need to specify the file_class in the second paramter -
// this class understands how to translate a http://www.youtube.com/ URI
// into Drupal's Youtube file scheme (youtube://).
$this->destination = new MigrateDestinationMedia('video', 'MigrateExtrasFileYoutube');
// We just need to map the 'value' in the media destination to the Youtube
// URI.
$this
->addFieldMapping('value', 'uri')
->xpath('uri');
$this
->addFieldMapping('field_video_description', 'description')
->xpath('description');
$this
->addFieldMapping('uid')
->defaultValue(1);
$this
->addUnmigratedDestinations(array(
'field_video_description:format',
'field_video_description:language',
'timestamp',
));
if (module_exists('path')) {
$this
->addUnmigratedDestinations(array(
'path',
));
}
}