public function MigrateSQLMap::saveIDMapping in Migrate 7.2
Same name and namespace in other branches
- 6.2 plugins/sources/sqlmap.inc \MigrateSQLMap::saveIDMapping()
Called upon import of one record, we record a mapping from the source key to the destination key. Also may be called, setting the third parameter to NEEDS_UPDATE, to signal an existing record should be remigrated.
Parameters
stdClass $source_row: The raw source data. We use the key map derived from the source object to get the source key values.
array $dest_ids: The destination key values.
int $needs_update: Status of the source row in the map. Defaults to STATUS_IMPORTED.
int $rollback_action: How to handle the destination object on rollback. Defaults to ROLLBACK_DELETE. $param string $hash If hashing is enabled, the hash of the raw source row.
Overrides MigrateMap::saveIDMapping
File
- plugins/
sources/ sqlmap.inc, line 418 - Defines a Drupal db-based implementation of MigrateMap.
Class
- MigrateSQLMap
- @file Defines a Drupal db-based implementation of MigrateMap.
Code
public function saveIDMapping(stdClass $source_row, array $dest_ids, $needs_update = MigrateMap::STATUS_IMPORTED, $rollback_action = MigrateMap::ROLLBACK_DELETE, $hash = NULL) {
migrate_instrument_start('saveIDMapping');
// Construct the source key.
$keys = array();
foreach ($this->sourceKeyMap as $field_name => $key_name) {
// A NULL key value will fail.
if (is_null($source_row->{$field_name})) {
Migration::displayMessage(t('Could not save to map table due to NULL value for key field !field', array(
'!field' => $field_name,
)));
migrate_instrument_stop('saveIDMapping');
return;
}
$keys[$key_name] = $source_row->{$field_name};
}
$fields = array(
'needs_update' => (int) $needs_update,
'rollback_action' => (int) $rollback_action,
'hash' => $hash,
);
$count = 1;
if (!empty($dest_ids)) {
foreach ($dest_ids as $dest_id) {
$fields['destid' . $count++] = $dest_id;
}
}
if ($this->trackLastImported) {
$fields['last_imported'] = time();
}
$this->connection
->merge($this->mapTable)
->key($keys)
->fields($fields)
->execute();
migrate_instrument_stop('saveIDMapping');
}