public function CsvDataSourceHandler::getListOfRelatedEntities in CRM Core 7
Returns related list entities from migration results.
This method based on the rows of csv file and ids. As result we can associate entities by line.
@todo: Allow more than one additional source key.
3 calls to CsvDataSourceHandler::getListOfRelatedEntities()
- CsvDataSourceHandler::getEntitiesForReferences in modules/
crm_core_data_import/ plugins/ source/ CsvDataSourceHandler.inc - Returns related list entities from migration results for references.
- CsvDataSourceHandler::getEntitiesForRelationships in modules/
crm_core_data_import/ plugins/ source/ CsvDataSourceHandler.inc - Returns related list entities from migration results for relationships.
- CsvDataSourceHandler::getEntitiesForUsers in modules/
crm_core_data_import/ plugins/ source/ CsvDataSourceHandler.inc - Returns related list entities from migration results for users.
File
- modules/
crm_core_data_import/ plugins/ source/ CsvDataSourceHandler.inc, line 149
Class
Code
public function getListOfRelatedEntities($settings, $item, CRMCoreDataImport $importer) {
$list = array();
if (!empty($settings)) {
foreach ($settings['fields'] as $plugin_data) {
list($source_type, $source_bundle, $source_delta) = explode(':', $plugin_data['source']);
list($destination_type, $destination_bundle, $destination_delta) = explode(':', $plugin_data['destination']);
// If current entity match to source entity in the plugin data.
if ($item['entity_type'] == $source_type && $item['bundle'] == $source_bundle && $item['delta'] == $source_delta) {
$machine_name = _crm_core_data_import_migration_machine_name($importer->id, $destination_type, $destination_bundle, $destination_delta);
$migration = Migration::getInstance($machine_name);
// Get related entity.
if ($migration) {
$map = $migration
->getMap();
$target_entity_id = db_select($map
->getMapTable(), 'map')
->fields('map', array(
'destid1',
))
->condition('map.sourceid1', $item['relation_id1'])
->execute()
->fetchField();
$source_entity = new stdClass();
$destination_entity = new stdClass();
$source_entity->id = $item['entity_id'];
$destination_entity->id = $target_entity_id;
// Add entity type to easily check entity type in settings.
$source_entity->entity_type = $source_type;
$destination_entity->entity_type = $destination_type;
// Add data to list.
$list[] = array(
'source_entity' => $source_entity,
'destination_entity' => $destination_entity,
'plugin_data' => $plugin_data,
);
}
}
}
}
return $list;
}