function drush_sf_import_sf_fieldmap in Salesforce Suite 7.2
Same name and namespace in other branches
- 6.2 sf_import/sf_import.drush.inc \drush_sf_import_sf_fieldmap()
Info about a specific fieldmap import
File
- sf_import/
sf_import.drush.inc, line 122 - Drush integration for Salesforce Import module. Provides commands to import Salesforce data.
Code
function drush_sf_import_sf_fieldmap($fieldmap_key = NULL) {
if (!$fieldmap_key) {
return _drush_sf_import_show_fieldmaps();
}
$map = salesforce_api_fieldmap_load($fieldmap_key);
if (empty($map)) {
drush_die('Invalid field map');
return;
}
$out = array();
// Display field mapping
$out[] = array(
'Name',
$map->name,
);
$out[] = array(
'Description',
$map->description,
);
$out[] = array(
'Drupal type',
$map->drupal_entity,
);
$out[] = array(
'Salesforce type',
$map->salesforce,
);
// Read the number of existing linked entries
$existing = db_query("\n SELECT COUNT(oid)\n FROM {salesforce_object_map}\n WHERE name = '%s'", $map->name)
->fetchField();
$out[] = array(
'Existing linked Drupal objects',
$existing,
);
// Read the number of entries on SF
if (!drush_get_option('no-sf', FALSE)) {
_sf_import_drush_check_soap();
try {
$sf = salesforce_api_connect();
if (!$sf) {
throw new Exception('Unable to connect to Salesforce');
}
$sql = "\n SELECT COUNT(Id)\n FROM " . $map->salesforce . "\n ";
$where = drush_get_option('where', FALSE);
if ($where) {
$sql .= "WHERE " . $where;
}
$query = $sf->client
->query($sql);
} catch (Exception $e) {
drush_set_error("Error while querying number of Salesforce entries : " . $e
->getMessage());
return;
}
$out[] = array(
'Rows in Salesforce',
$query->records[0]->any,
);
}
drush_print('General information:');
drush_print_table($out, FALSE);
drush_print("\nMap information:");
$out = array(
array(
'Salesforce',
'',
'Drupal',
),
);
/*
$dr_def = salesforce_api_fieldmap_objects_load('drupal', $map->drupal_entity);
$sf_def = salesforce_api_fieldmap_objects_load('salesforce', $map->salesforce);
*/
foreach ($map->fields as $sf_fieldname => $dr_fieldname) {
$out[] = array(
$sf_fieldname,
'<=>',
$dr_fieldname,
);
}
drush_print_table($out, TRUE);
}