fixed csv import:

- no more caching in the cat_id function, as it's done in the categories class in the API no
- categories::name2id no longer caches not found entries, as they might be added in this request
- contacts_sql::add set's all unset telefon numbers to '', to avoid the stupid db-default '+1 (000) 000-0000', which I dont want to change in the stable release
This commit is contained in:
Ralf Becker 2006-04-14 09:50:39 +00:00
parent bba94d054e
commit dc68edab46
3 changed files with 27 additions and 40 deletions

View File

@ -36,7 +36,7 @@
$GLOBALS['egw']->redirect_link('/addressbook/index.php');
}
$GLOBALS['egw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook');
$GLOBALS['egw']->common->phpgw_header();
$GLOBALS['egw']->common->egw_header();
$GLOBALS['egw']->contacts = createobject('phpgwapi.contacts');
@ -81,51 +81,36 @@
return False;
}
$cat2id = array();
function cat_id($cats)
{
if(!$cats)
{
return '';
}
if(!is_object($GLOBALS['egw']->categories))
{
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories');
}
$ids = array();
foreach(split(' *[,;] *',$cats) as $cat)
{
if(isset($cat2id[$cat]))
if (is_numeric($cat) && $GLOBALS['egw']->categories->id2name($cat) != '--')
{
$ids[$cat] = $cat2id[$cat]; // cat is in cache
$id = (int) $cat;
}
elseif ($id = $GLOBALS['egw']->categories->name2id(addslashes($cat)))
{
// cat exists
}
else
{
if(!is_object($GLOBALS['egw']->categories))
{
$GLOBALS['egw']->categories = createobject('phpgwapi.categories');
}
if (is_numeric($cat) && $GLOBALS['egw']->categories->id2name($cat) != '--')
{
$cat2id[$cat] = $ids[$cat] = $cat;
}
elseif ($id = $GLOBALS['egw']->categories->name2id(addslashes($cat)))
{ // cat exists
$cat2id[$cat] = $ids[$cat] = $id;
}
else
{ // create new cat
$GLOBALS['egw']->categories->add(array('name' => $cat,'descr' => $cat));
$cat2id[$cat] = $ids[$cat] = $GLOBALS['egw']->categories->name2id(addslashes($cat));
}
{ // create new cat
$id = $GLOBALS['egw']->categories->add(array('name' => $cat,'descr' => $cat));
}
$ids[$id] = $id; // we use the $id as index to not ass a cat twice
}
$id_str = implode(',',$ids);
if(count($ids) > 1) // multiple cats need to be in ','
{
$id_str = ",$id_str,";
}
return $id_str;
return implode(',',$ids);
}
if (!is_object($GLOBALS['egw']->html))
{
$GLOBALS['egw']->html = CreateObject('phpgwapi.html');
@ -410,7 +395,7 @@
$empty = !count($values);
// convert the category name to an id
if ($values['cat_id'] && !is_numeric($values['cat_id']) && $values['cat_id'][0] != ',')
if ($values['cat_id'])
{
$values['cat_id'] = cat_id($values['cat_id']);
}
@ -438,9 +423,8 @@
}
if(!$_POST['debug'] && !$empty) // dont import empty contacts
{
$GLOBALS['egw']->contacts->add( $values['owner'] ? $values['owner'] : $GLOBALS['egw_info']['user']['account_id'],
$values);
// echo "<p>adding: ".print_r($values)."</p>\n";
$GLOBALS['egw']->contacts->add( $values['owner'] ? $values['owner'] : $GLOBALS['egw_info']['user']['account_id'],$values);
//echo "<p>adding: ".print_r($values,true)."</p>\n";
}
}
$log .= "\t</tr>\n</table>\n";
@ -459,5 +443,5 @@
$GLOBALS['egw']->template->set_var('hiddenvars',str_replace('{','&#x7B;',$hiddenvars));
$GLOBALS['egw']->template->pfp('out','import',True);
$GLOBALS['egw']->common->phpgw_footer();
$GLOBALS['egw']->common->egw_footer();
?>

View File

@ -607,7 +607,9 @@
'(cat_owner = '.(int)$this->account_id.' OR cat_owner = -1)',
),__LINE__,__FILE__);
return $cache[$cat_name] = $this->db->next_record() ? $this->db->f('cat_id') : 0;
if (!$this->db->next_record()) return 0; // cat not found, dont cache it, as it might be created in this request
return $cache[$cat_name] = (int) $this->db->f('cat_id');
}
/**

View File

@ -610,10 +610,11 @@
{
$fields['tid'] = 'n';
}
// setting the following fields to empty if unset, as the addressbook does not seem to set them anymore and I dont want to change the db-default atm.
foreach(array('tel_voice','tel_bbs','tel_modem') as $name)
// setting the telephone numbers to empty if unset, as otherwise the db-default adds '+1 (000) 000-0000'
// I dont want to change the default in the stable release
foreach($this->stock_contact_fields as $name)
{
if (!isset($fields[$name])) $fields[$name] = '';
if (substr($name,0,4) == 'tel_' && !isset($fields[$name])) $fields[$name] = '';
}
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);