public function BeerCommentMigration::__construct in Migrate 7.2
Same name and namespace in other branches
- 6.2 migrate_example/beer.inc \BeerCommentMigration::__construct()
General initialization of a Migration object.
Overrides BasicExampleMigration::__construct
File
- migrate_example/
beer.inc, line 500 - A basic example of using the Migrate module to import taxonomy, users, nodes, and comments.
Class
- BeerCommentMigration
- Import items from the migrate_example_beer_comment table and make them into Drupal comment objects.
Code
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = 'Comments about beers';
$query = db_select('migrate_example_beer_comment', 'mec')
->fields('mec', array(
'cid',
'cid_parent',
'name',
'mail',
'aid',
'body',
'bid',
'subject',
))
->orderBy('cid_parent', 'ASC');
$this->source = new MigrateSourceSQL($query);
// Note that the machine name passed for comment migrations is
// 'comment_node_' followed by the machine name of the node type these
// comments are attached to.
$this->destination = new MigrateDestinationComment('comment_node_migrate_example_beer');
$this->map = new MigrateSQLMap($this->machineName, array(
'cid' => array(
'type' => 'int',
'not null' => TRUE,
),
), MigrateDestinationComment::getKeySchema());
// Mapped fields
$this
->addSimpleMappings(array(
'name',
'subject',
'mail',
));
$this
->addFieldMapping('status')
->defaultValue(COMMENT_PUBLISHED);
$this
->addFieldMapping('nid', 'bid')
->sourceMigration('BeerNode');
$this
->addFieldMapping('uid', 'aid')
->sourceMigration('BeerUser')
->defaultValue(0);
$this
->addFieldMapping('pid', 'cid_parent')
->sourceMigration('BeerComment')
->description('Parent comment.');
$this
->addFieldMapping('comment_body', 'body');
// No unmapped source fields
// Unmapped destination fields
$this
->addUnmigratedDestinations(array(
'changed',
'comment_body:format',
'created',
'homepage',
'hostname',
'language',
'thread',
));
$destination_fields = $this->destination
->fields();
if (isset($destination_fields['path'])) {
$this
->addFieldMapping('path')
->issueGroup(t('DNM'));
if (isset($destination_fields['pathauto'])) {
$this
->addFieldMapping('pathauto')
->issueGroup(t('DNM'));
}
}
}