From 3656ce851588772a292334a6823d808ae64f0b31 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 25 Jan 2012 18:13:57 +0000 Subject: [PATCH] - Leave any account names that can't be parsed to IDs for use in errors - Return warning about any names that can't be parsed --- .../class.importexport_helper_functions.inc.php | 10 +++++++++- .../inc/class.importexport_import_csv.inc.php | 14 +++++++++++++- importexport/lang/egw_en.lang | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/importexport/inc/class.importexport_helper_functions.inc.php b/importexport/inc/class.importexport_helper_functions.inc.php index 7efc1b046c..273c327bf7 100755 --- a/importexport/inc/class.importexport_helper_functions.inc.php +++ b/importexport/inc/class.importexport_helper_functions.inc.php @@ -94,11 +94,12 @@ class importexport_helper_functions { * @param mixed $_account_lid comma seperated list or array with lids * @return mixed comma seperated list or array with ids */ - public static function account_name2id( $_account_lids ) { + public static function account_name2id( &$_account_lids ) { $account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids ); $skip = false; foreach ( $account_lids as $key => $account_lid ) { if($skip) { + unset($account_lids[$key]); $skip = false; continue; } @@ -106,6 +107,7 @@ class importexport_helper_functions { // Handle any IDs that slip in if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { + unset($account_lids[$key]); $account_ids[] = (int)$account_lid; continue; } @@ -113,23 +115,29 @@ class importexport_helper_functions { // Do this first, in case their first name matches a username if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) { $account_ids[] = $account_id; + unset($account_lids[$key]); $skip = true; // Skip the next one, it's the first name continue ; } if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) { $account_ids[] = $account_id; + unset($account_lids[$key]); continue; } if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid, 'account_fullname' )) { $account_ids[] = $account_id; + unset($account_lids[$key]); continue; } // Handle groups listed as Group, if ( $account_lid[0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid))) { $account_ids[] = $account_id; + unset($account_lids[$key-1]); + unset($account_lids[$key]); } } + $_account_lids = (is_array($_account_lids) ? $account_lids : implode(',',$account_lids)); return is_array( $_account_lids ) ? $account_ids : implode( ',', (array)$account_ids ); } // end of member function account_lid2id diff --git a/importexport/inc/class.importexport_import_csv.inc.php b/importexport/inc/class.importexport_import_csv.inc.php index cfd3118df2..f36cb5e95b 100755 --- a/importexport/inc/class.importexport_import_csv.inc.php +++ b/importexport/inc/class.importexport_import_csv.inc.php @@ -257,8 +257,12 @@ class importexport_import_csv implements importexport_iface_import_record { //, * @param $appname Appname for custom field parsing * @param $selects Array of select values to be automatically parsed * @param $format int 0 if records are supposed to be in DB format, 1 to treat as human values (Used for dates and select-cat) + * + * @return string warnings, if any */ public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) { + $warnings = array(); + // Automatic conversions if($appname) { if(!self::$cf_parse_cache[$appname]) { @@ -293,8 +297,16 @@ class importexport_import_csv implements importexport_iface_import_record { //, if ($record[$name]) { // Automatically handle text owner without explicit translation $new_owner = importexport_helper_functions::account_name2id($record[$name]); + if(count($new_owner) != count(explode(',',$record[$name]))) + { + // Unable to parse value into account + $warnings[] = lang('%1 is not a known user or group', $record[$name]); + } if($new_owner != '') { $record[$name] = $new_owner; + } else { + // Clear it to prevent trouble later on + $record[$name] = ''; } } } @@ -370,7 +382,7 @@ class importexport_import_csv implements importexport_iface_import_record { //, $GLOBALS['egw_info']['flags']['currentapp'] = $current_app; } - return; + return implode("\n",$warnings); } } // end of import_csv ?> diff --git a/importexport/lang/egw_en.lang b/importexport/lang/egw_en.lang index bbea2da2ba..07e906728d 100644 --- a/importexport/lang/egw_en.lang +++ b/importexport/lang/egw_en.lang @@ -1,5 +1,6 @@ %1 definition(s) %2 importexport en %1 definition(s) %2 %1 definition(s) %2, %3 failed because of insufficent rights !!! importexport en %1 definition(s) %2, %3 failed because of insufficient rights !!! +%1 is not a known user or group importexport en %1 is not a known user or group %1 is not readable importexport en %1 is not readable. %1 is not writable importexport en %1 is not writable. %1 records processed importexport en %1 records processed.