public function WineUpdatesMigration::__construct in Migrate 7.2
Same name and namespace in other branches
- 6.2 migrate_example/wine.inc \WineUpdatesMigration::__construct()
General initialization of a Migration object.
Overrides AdvancedExampleMigration::__construct
File
- migrate_example/
wine.inc, line 1583 - Advanced migration examples. These serve two purposes:
Class
- WineUpdatesMigration
- TIP: This demonstrates a migration designed not to import new content, but to update existing content (in this case, revised wine ratings)
Code
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Update wine ratings');
$query = db_select('migrate_example_wine_updates', 'w')
->fields('w', array(
'wineid',
'rating',
));
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationNode('migrate_example_wine');
$this->map = new MigrateSQLMap($this->machineName, array(
'wineid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Wine ID',
'alias' => 'w',
),
), MigrateDestinationNode::getKeySchema());
// Indicate we're updating existing data. The default, Migration::SOURCE,
// would cause existing nodes to be completely replaced by the source data.
// In this case, the existing node will be loaded and only the rating
// altered.
$this->systemOfRecord = Migration::DESTINATION;
// Mapped fields
// The destination handler needs the nid to change - since the incoming data
// has a source id, not a nid, we need to apply the original wine migration
// mapping to populate the nid.
$this
->addFieldMapping('nid', 'wineid')
->sourceMigration('WineWine');
$this
->addFieldMapping('field_migrate_example_wine_ratin', 'rating');
// No unmapped source fields
// Unmapped destination fields - these will be left unchanged in this case
// (normally they would be overwritten with their default values).
$this
->addFieldMapping('uid');
$this
->addFieldMapping('migrate_example_wine_varieties');
$this
->addFieldMapping('migrate_example_wine_regions');
$this
->addFieldMapping('migrate_example_wine_best_with');
$this
->addFieldMapping('body');
$this
->addFieldMapping('field_migrate_example_image');
$this
->addFieldMapping('sticky');
$this
->addFieldMapping('created');
$this
->addFieldMapping('changed');
$this
->addUnmigratedDestinations(array(
'body:format',
'body:summary',
'comment',
'field_migrate_example_image:alt',
'field_migrate_example_image:destination_dir',
'field_migrate_example_image:destination_file',
'field_migrate_example_image:file_class',
'field_migrate_example_image:file_replace',
'field_migrate_example_image:preserve_files',
'field_migrate_example_image:source_dir',
'field_migrate_example_image:title',
'field_migrate_example_image:urlencode',
'field_migrate_example_top_vintag',
'is_new',
'language',
'log',
'migrate_example_wine_best_with:source_type',
'migrate_example_wine_best_with:create_term',
'migrate_example_wine_best_with:ignore_case',
'migrate_example_wine_regions:source_type',
'migrate_example_wine_regions:create_term',
'migrate_example_wine_regions:ignore_case',
'migrate_example_wine_varieties:source_type',
'migrate_example_wine_varieties:create_term',
'migrate_example_wine_varieties:ignore_case',
'promote',
'revision',
'revision_uid',
'status',
'title',
'tnid',
'translate',
));
if (module_exists('statistics')) {
$this
->addUnmigratedDestinations(array(
'totalcount',
'daycount',
'timestamp',
));
}
}