* CardDAV/Addressbook: fixed various issues with groups/distribution lists as supported by Apple and eMclient (groups need to be enabled in CalDAV/CardDAV preferences!)

This commit is contained in:
Ralf Becker 2013-08-02 19:31:59 +00:00
parent b2659058ef
commit c61ccc9372
2 changed files with 43 additions and 22 deletions

View File

@ -1742,6 +1742,13 @@ class addressbook_bo extends addressbook_so
return $success;
}
/**
* Some caching for lists within request
*
* @var array
*/
private static $list_cache = array();
/**
* Check if user has required rights for a list or list-owner
*
@ -1773,7 +1780,15 @@ class addressbook_bo extends addressbook_so
{
if (!$this->check_list(null,EGW_ACL_ADD|EGW_ACL_EDIT,$owner)) return false;
return parent::add_list($keys,$owner,$contacts,$data);
try {
$ret = parent::add_list($keys,$owner,$contacts,$data);
if ($ret) unset(self::$list_cache[$ret]);
}
// catch sql error, as creating same name&owner list gives a sql error doublicate key
catch(egw_exception_db $e) {
return false;
}
return $ret;
}
/**
@ -1788,6 +1803,8 @@ class addressbook_bo extends addressbook_so
{
if (!$this->check_list($list,EGW_ACL_EDIT)) return false;
unset(self::$list_cache[$list]);
return parent::add2list($contact,$list,$existing);
}
@ -1802,6 +1819,15 @@ class addressbook_bo extends addressbook_so
{
if ($list && !$this->check_list($list,EGW_ACL_EDIT)) return false;
if ($list)
{
unset(self::$list_cache[$list]);
}
else
{
self::$list_cache = array();
}
return parent::remove_from_list($contact,$list);
}
@ -1815,6 +1841,11 @@ class addressbook_bo extends addressbook_so
{
if (!$this->check_list($list,EGW_ACL_DELETE)) return false;
foreach((array)$list as $l)
{
unset(self::$list_cache[$l]);
}
return parent::delete_list($list);
}
@ -1826,11 +1857,9 @@ class addressbook_bo extends addressbook_so
*/
function read_list($list)
{
static $cache;
if (isset(self::$list_cache[$list])) return self::$list_cache[$list];
if (isset($cache[$list])) return $cache[$list];
return $cache[$list] = parent::read_list($list);
return self::$list_cache[$list] = parent::read_list($list);
}
/**

View File

@ -208,7 +208,7 @@ class addressbook_groupdav extends groupdav_handler
}
}
// add groups after contacts, but only if enabled and NOT for '/addressbook/' (!isset($filter['owner'])
if (in_array('D',$this->home_set_pref) && (!$start || count($contacts) < $start[1]) && isset($filter['owner']))
if (in_array('D',$this->home_set_pref) && (!$start || count($contacts) < $start[1]))
{
$where = array(
'list_owner' => isset($filter['owner'])?$filter['owner']:array_keys($this->bo->grants)
@ -561,17 +561,8 @@ class addressbook_groupdav extends groupdav_handler
if (!isset($contact['etag']))
{
if ($is_group)
{
if (($contact = $this->bo->read_list($save_ok)))
{
$contact = egw_db::strip_array_keys($contact, 'list_');
}
}
else
{
$contact = $this->bo->read($save_ok);
}
// epl-11.1 does not store carddav_name for lists, so we need to generate it here
$contact = $this->read($is_group ? common::generate_uid('addressbook-lists', $save_ok) : $contact['carddav_name'], $options['path']);
//error_log(__METHOD__."(, $id, '$user') read(_list)($save_ok) returned ".array2string($contact));
}
@ -596,7 +587,7 @@ class addressbook_groupdav extends groupdav_handler
if (!isset($contact['owner'])) $contact['owner'] = $GLOBALS['egw_info']['user']['account_id'];
foreach(array('id','carddav_name','uid','owner') as $name)
{
if ($name != self::$path_attr) $data['list_'.$name] = $contact[$name];
$data['list_'.$name] = $contact[$name];
}
//error_log(__METHOD__.'('.array2string($contact).', '.array2string($oldContact).') data='.array2string($data));
if (($list_id=$this->bo->add_list(array('list_'.self::$path_attr => $contact[self::$path_attr]),
@ -646,10 +637,11 @@ class addressbook_groupdav extends groupdav_handler
if ($to_add_ids) $this->bo->add2list($to_add_ids, $list_id, array());
if ($to_delete_ids) $this->bo->remove_from_list($to_delete_ids, $list_id);
}
// reread as update of list-members updates etag and modified
$contact = $this->bo->read_list($list_id);
}
if ($this->debug > 1) error_log(__METHOD__.'('.array2string($contact).', '.array2string($oldContact).') on return contact='.array2string($data).' returning '.array2string($list_id));
$contact = $data;
return $list_id;
return $list_id;
}
/**
@ -670,8 +662,8 @@ class addressbook_groupdav extends groupdav_handler
$user = array_merge((array)$user,array_keys($this->get_shared(true))); // true: ignore all-in-one pref
}
$ctag = $this->bo->get_ctag($user);
// include lists-ctag, if enabled and NOT in /addressbook/ (we dont sync distribution-lists/groups there)
if (in_array('D',$this->home_set_pref) && $path != '/addressbook/')
// include lists-ctag, if enabled
if (in_array('D',$this->home_set_pref))
{
$lists_ctag = $this->bo->lists_ctag($user);
}