mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
- 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
This commit is contained in:
parent
abe6ce3482
commit
3656ce8515
@ -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, <name>
|
||||
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
|
||||
|
@ -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
|
||||
?>
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user