* 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 16:31:54 +00:00
parent 1581547086
commit afd034aca6
2 changed files with 43 additions and 13 deletions

View File

@ -1776,6 +1776,13 @@ class addressbook_bo extends addressbook_so
return $success; 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 * Check if user has required rights for a list or list-owner
* *
@ -1807,7 +1814,15 @@ class addressbook_bo extends addressbook_so
{ {
if (!$this->check_list(null,EGW_ACL_ADD|EGW_ACL_EDIT,$owner)) return false; 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_invalid_sql $e) {
return false;
}
return $ret;
} }
/** /**
@ -1822,6 +1837,8 @@ class addressbook_bo extends addressbook_so
{ {
if (!$this->check_list($list,EGW_ACL_EDIT)) return false; if (!$this->check_list($list,EGW_ACL_EDIT)) return false;
unset(self::$list_cache[$list]);
return parent::add2list($contact,$list,$existing); return parent::add2list($contact,$list,$existing);
} }
@ -1836,6 +1853,15 @@ class addressbook_bo extends addressbook_so
{ {
if ($list && !$this->check_list($list,EGW_ACL_EDIT)) return false; 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); return parent::remove_from_list($contact,$list);
} }
@ -1849,6 +1875,11 @@ class addressbook_bo extends addressbook_so
{ {
if (!$this->check_list($list,EGW_ACL_DELETE)) return false; 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); return parent::delete_list($list);
} }
@ -1860,11 +1891,9 @@ class addressbook_bo extends addressbook_so
*/ */
function read_list($list) 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 self::$list_cache[$list] = parent::read_list($list);
return $cache[$list] = parent::read_list($list);
} }
/** /**

View File

@ -243,7 +243,7 @@ class addressbook_groupdav extends groupdav_handler
} }
} }
// add groups after contacts, but only if enabled and NOT for '/addressbook/' (!isset($filter['owner']) // 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( $where = array(
'list_owner' => isset($filter['owner'])?$filter['owner']:array_keys($this->bo->grants) 'list_owner' => isset($filter['owner'])?$filter['owner']:array_keys($this->bo->grants)
@ -284,9 +284,9 @@ class addressbook_groupdav extends groupdav_handler
} }
$files[] = $this->add_resource($path, $list, $props); $files[] = $this->add_resource($path, $list, $props);
if ($sync_collection_report && $this->sync_collection_token < $list['list_modified']) if ($sync_collection_report && $this->sync_collection_token < ($ts=$GLOBALS['egw']->db->from_timestamp($list['list_modified'])))
{ {
$this->sync_collection_token = $list['list_modified']; $this->sync_collection_token = $ts;
} }
} }
} }
@ -660,7 +660,7 @@ class addressbook_groupdav extends groupdav_handler
if (!isset($contact['owner'])) $contact['owner'] = $GLOBALS['egw_info']['user']['account_id']; if (!isset($contact['owner'])) $contact['owner'] = $GLOBALS['egw_info']['user']['account_id'];
foreach(array('id','carddav_name','uid','owner') as $name) 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)); //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]), if (($list_id=$this->bo->add_list(array('list_'.self::$path_attr => $contact[self::$path_attr]),
@ -710,10 +710,11 @@ class addressbook_groupdav extends groupdav_handler
if ($to_add_ids) $this->bo->add2list($to_add_ids, $list_id, array()); 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); 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)); 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;
} }
/** /**
@ -738,8 +739,8 @@ class addressbook_groupdav extends groupdav_handler
$user = array_merge((array)$user,array_keys($this->get_shared(true))); // true: ignore all-in-one pref $user = array_merge((array)$user,array_keys($this->get_shared(true))); // true: ignore all-in-one pref
} }
$ctag = $this->bo->get_ctag($user); $ctag = $this->bo->get_ctag($user);
// include lists-ctag, if enabled and NOT in /addressbook/ (we dont sync distribution-lists/groups there) // include lists-ctag, if enabled
if (in_array('D',$this->home_set_pref) && $path != '/addressbook/') if (in_array('D',$this->home_set_pref))
{ {
$lists_ctag = $this->bo->lists_ctag($user); $lists_ctag = $this->bo->lists_ctag($user);
} }