From 1f46ac05165de99a4d557ced25900ccebcec0e77 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 27 Jan 2015 21:20:02 +0000 Subject: [PATCH] Import warning improvements: - Only warn once about missing contact type - Do not try to check header if definition says there is no header --- .../class.addressbook_import_contacts_csv.inc.php | 13 +++++++++++-- .../inc/class.importexport_basic_import_csv.inc.php | 1 - .../inc/class.importexport_import_ui.inc.php | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/addressbook/inc/class.addressbook_import_contacts_csv.inc.php b/addressbook/inc/class.addressbook_import_contacts_csv.inc.php index 107a4f6e38..695db5181f 100644 --- a/addressbook/inc/class.addressbook_import_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_import_contacts_csv.inc.php @@ -33,6 +33,11 @@ class addressbook_import_contacts_csv extends importexport_basic_import_csv { */ protected $tracking; + /** + * @var boolean If import file has no type, it can generate a lot of warnings. + * Users don't like this, so we only warn once. + */ + private $type_warned = false; /** * imports entries according to given definition object. @@ -56,7 +61,6 @@ class addressbook_import_contacts_csv extends importexport_basic_import_csv { $this->lookups['tid'][$tid] = $data['name']; } - // set contact owner $contact_owner = isset( $_definition->plugin_options['contact_owner'] ) ? $_definition->plugin_options['contact_owner'] : $this->user; @@ -122,7 +126,12 @@ class addressbook_import_contacts_csv extends importexport_basic_import_csv { // Do not import into non-existing type, warn and change if(!$record->tid || !$this->lookups['tid'][$record->tid]) { - $this->warnings[$import_csv->get_current_position()] = lang('Unknown type %1, imported as %2',$record->tid,lang($this->lookups['tid']['n'])); + // Avoid lots of warnings about type (2 types are contact and deleted) + if(!$this->type_warned || count($this->lookups['tid']) == 2 ) + { + $this->warnings[$import_csv->get_current_position()] = lang('Unknown type %1, imported as %2',$record->tid,lang($this->lookups['tid']['n'])); + $this->type_warned = true; + } $record->tid = 'n'; } diff --git a/importexport/inc/class.importexport_basic_import_csv.inc.php b/importexport/inc/class.importexport_basic_import_csv.inc.php index 5fae9d9aa5..8144da9fb0 100644 --- a/importexport/inc/class.importexport_basic_import_csv.inc.php +++ b/importexport/inc/class.importexport_basic_import_csv.inc.php @@ -434,7 +434,6 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor // Set up HTML $rows['h1'] = $labels; - error_log("Wow, ".count($this->preview_records) . ' preveiw records'); foreach($this->preview_records as $i => $row_data) { // Convert to human-friendly diff --git a/importexport/inc/class.importexport_import_ui.inc.php b/importexport/inc/class.importexport_import_ui.inc.php index 581e8f15e0..1b95daf174 100644 --- a/importexport/inc/class.importexport_import_ui.inc.php +++ b/importexport/inc/class.importexport_import_ui.inc.php @@ -359,6 +359,9 @@ // Only CSV files if(!$options['csv_fields']) return true; + // Can't check if definition has no header + if($options['num_header_lines'] == 0) return true; + $preference = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; $charset = $options['charset'] == 'user' || !$options['charset'] ? $preference : $options['charset'];