diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index 1de9ef6413..6d5604c3ba 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -1776,6 +1776,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 * @@ -1807,7 +1814,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; } /** @@ -1822,6 +1837,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); } @@ -1836,6 +1853,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); } @@ -1849,6 +1875,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); } @@ -1860,11 +1891,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); } /** diff --git a/addressbook/inc/class.addressbook_groupdav.inc.php b/addressbook/inc/class.addressbook_groupdav.inc.php index e560c4bc24..e47bf85813 100644 --- a/addressbook/inc/class.addressbook_groupdav.inc.php +++ b/addressbook/inc/class.addressbook_groupdav.inc.php @@ -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']) - 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) @@ -284,9 +284,9 @@ class addressbook_groupdav extends groupdav_handler } $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; } } } @@ -626,17 +626,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)); } @@ -661,7 +652,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]), @@ -711,10 +702,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; } /** @@ -739,8 +731,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); }