Improve handling of headers, checking translations and message_id

This commit is contained in:
Nathan Gray 2013-04-23 20:04:51 +00:00
parent 288469e66c
commit fc8bb745d7
2 changed files with 38 additions and 7 deletions

View File

@ -172,6 +172,8 @@ class importexport_export_csv implements importexport_iface_export_record
foreach($this->mapping as $field => &$label) foreach($this->mapping as $field => &$label)
{ {
if($fields[$field]) $label = $fields[$field]; if($fields[$field]) $label = $fields[$field];
// Make sure no *
if(substr($label,-1) == '*') $label = substr($label,0,-1);
} }
} catch (Exception $e) { } catch (Exception $e) {
translation::add_app($appname); translation::add_app($appname);

View File

@ -361,16 +361,45 @@
// Skipped column in definition // Skipped column in definition
continue; continue;
} }
// Check column headers, taking into account different translations else if ($index > count($options['csv_fields']))
elseif($index < count($options['csv_fields']) && strtoupper($options['csv_fields'][$index]) != strtoupper($header) && strtoupper(lang($options['csv_fields'][$index])) != strtoupper($header) && strtoupper($options['csv_fields'][$index]) != strtoupper(lang($header)))
{ {
// File has extra columns - already warned, above
break;
}
// Check for matching headers
if($options['csv_fields'][$index] == $header)
{
// Simple match
continue;
}
// Check column headers, taking into account different translations - make sure no *
$lang_defn = mb_strtoupper(translation::translate($options['csv_fields'][$index],false,''));
$lang_file = mb_strtoupper(translation::translate($header,false,''));
if($lang_defn == $lang_file ||
$lang_defn == mb_strtoupper($header) ||
$lang_file == mb_strtoupper($options['csv_fields'][$index])
)
{
continue;
}
// Try to go back to translation message ID for a match
$file_message_id = translation::get_message_id($header, $definition->application);
$defn_message_id = translation::get_message_id($options['csv_fields'][$index], $definition->application);
if($file_message_id && $defn_message_id && $file_message_id == $defn_message_id)
{
continue;
}
// Problem // Problem
$message[] = lang("Column mismatch: %1 should be %2, not %3", $message[] = lang("Column mismatch: %1 should be %2, not %3",
$index,$options['csv_fields'][$index], $header); $index,$options['csv_fields'][$index], $header);
// But can still continue // But can still continue
// $ok = false; // $ok = false;
} }
}
if(!$ok || count($message) != $message_count) if(!$ok || count($message) != $message_count)
{ {
// Add links for new / edit definition // Add links for new / edit definition