mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 23:00:56 +01:00
Use similar_text() to try to automatically match import field names to application fields when there's no exact match
This commit is contained in:
parent
91545df1e6
commit
9de3b4afc9
@ -138,11 +138,13 @@ class importexport_wizard_basic_import_csv
|
|||||||
# Copy already set, but allow new file to update
|
# Copy already set, but allow new file to update
|
||||||
$content['field_mapping'][$index] = $content['plugin_options']['field_mapping'][$index];
|
$content['field_mapping'][$index] = $content['plugin_options']['field_mapping'][$index];
|
||||||
}
|
}
|
||||||
|
$best_match = '';
|
||||||
|
$best_match_value = 0;
|
||||||
foreach($this->mapping_fields as $key => $field_name) {
|
foreach($this->mapping_fields as $key => $field_name) {
|
||||||
if(is_array($field_name)) continue;
|
if(is_array($field_name)) continue;
|
||||||
if(strcasecmp($field, $field_name) == 0 || strcasecmp($field,$key) == 0) {
|
if(strcasecmp($field, $field_name) == 0 || strcasecmp($field,$key) == 0) {
|
||||||
$content['field_mapping'][$index] = $key;
|
$content['field_mapping'][$index] = $key;
|
||||||
continue;
|
continue 2;
|
||||||
}
|
}
|
||||||
// Check english also
|
// Check english also
|
||||||
if($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != 'en' && !isset($english[$field_name])) {
|
if($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != 'en' && !isset($english[$field_name])) {
|
||||||
@ -155,8 +157,22 @@ class importexport_wizard_basic_import_csv
|
|||||||
}
|
}
|
||||||
if($english[$field_name] && strcasecmp($field, $english[$field_name]) == 0) {
|
if($english[$field_name] && strcasecmp($field, $english[$field_name]) == 0) {
|
||||||
$content['field_mapping'][$index] = $key;
|
$content['field_mapping'][$index] = $key;
|
||||||
continue;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for similar but slightly different
|
||||||
|
$match = 0;
|
||||||
|
if(similar_text(strtolower($field), strtolower($field_name), $match) &&
|
||||||
|
$match > 85 &&
|
||||||
|
$match > $best_match_value
|
||||||
|
) {
|
||||||
|
$best_match = $key;
|
||||||
|
$best_match_value = $match;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if($best_match) {
|
||||||
|
$content['field_mapping'][$index] = $best_match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif($content['plugin_options']['csv_fields']) {
|
} elseif($content['plugin_options']['csv_fields']) {
|
||||||
|
Loading…
Reference in New Issue
Block a user