Use md5 again. Reverted 4054953039

This commit is contained in:
Aleksander Machniak (Kolab Systems) 2011-07-08 11:38:26 +02:00
parent 20c57736f5
commit 6994d3d38f

View file

@ -62,6 +62,7 @@ class rcube_kolab_contacts extends rcube_addressbook
private $contacts; private $contacts;
private $distlists; private $distlists;
private $groupmembers; private $groupmembers;
private $id2uid;
private $filter; private $filter;
private $result; private $result;
private $namespace; private $namespace;
@ -512,6 +513,7 @@ class rcube_kolab_contacts extends rcube_addressbook
$contact = $this->_to_rcube_contact($object); $contact = $this->_to_rcube_contact($object);
$id = $contact['ID']; $id = $contact['ID'];
$this->contacts[$id] = $contact; $this->contacts[$id] = $contact;
$this->id2uid[$id] = $object['uid'];
$insert_id = $id; $insert_id = $id;
} }
} }
@ -533,8 +535,8 @@ class rcube_kolab_contacts extends rcube_addressbook
{ {
$updated = false; $updated = false;
$this->_fetch_contacts(); $this->_fetch_contacts();
if ($this->contacts[$id]) { if ($this->contacts[$id] && ($uid = $this->id2uid[$id])) {
$old = $this->contactstorage->getObject($id); $old = $this->contactstorage->getObject($uid);
$object = array_merge($old, $this->_from_rcube_contact($save_data)); $object = array_merge($old, $this->_from_rcube_contact($save_data));
$saved = $this->contactstorage->save($object, $uid); $saved = $this->contactstorage->save($object, $uid);
@ -570,23 +572,25 @@ class rcube_kolab_contacts extends rcube_addressbook
$count = 0; $count = 0;
foreach ($ids as $id) { foreach ($ids as $id) {
$deleted = $this->contactstorage->delete($id); if ($uid = $this->id2uid[$id]) {
$deleted = $this->contactstorage->delete($uid);
if (PEAR::isError($deleted)) { if (PEAR::isError($deleted)) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error deleting a contact object from the Kolab server:" . $deleted->getMessage()), 'message' => "Error deleting a contact object from the Kolab server:" . $deleted->getMessage()),
true, false); true, false);
} }
else { else {
// remove from distribution lists // remove from distribution lists
foreach ((array)$this->groupmembers[$id] as $gid) foreach ((array)$this->groupmembers[$id] as $gid)
$this->remove_from_group($gid, $id); $this->remove_from_group($gid, $id);
// clear internal cache // clear internal cache
unset($this->contacts[$id], $this->groupmembers[$id]); unset($this->contacts[$id], $this->id2uid[$id], $this->groupmembers[$id]);
$count++; $count++;
}
} }
} }
@ -603,6 +607,7 @@ class rcube_kolab_contacts extends rcube_addressbook
if (!PEAR::isError($this->contactstorage->deleteAll())) { if (!PEAR::isError($this->contactstorage->deleteAll())) {
$this->contacts = array(); $this->contacts = array();
$this->id2uid = array();
$this->result = null; $this->result = null;
} }
} }
@ -645,8 +650,9 @@ class rcube_kolab_contacts extends rcube_addressbook
return false; return false;
} }
else { else {
$id = md5($list['uid']);
$this->distlists[$record['ID']] = $list; $this->distlists[$record['ID']] = $list;
$result = array('id' => $list['uid'], 'name' => $name); $result = array('id' => $id, 'name' => $name);
} }
return $result; return $result;
@ -734,10 +740,11 @@ class rcube_kolab_contacts extends rcube_addressbook
$ids = array_diff($ids, $exists); $ids = array_diff($ids, $exists);
foreach ($ids as $contact_id) { foreach ($ids as $contact_id) {
if ($contact = $this->contacts[$contact_id]) { if ($uid = $this->id2uid[$contact_id]) {
$contact = $this->contacts[$contact_id];
foreach ($this->get_col_values('email', $contact, true) as $email) { foreach ($this->get_col_values('email', $contact, true) as $email) {
$list['member'][] = array( $list['member'][] = array(
'uid' => $contact_id, 'uid' => $uid,
'display-name' => $contact['name'], 'display-name' => $contact['name'],
'smtp-address' => $email, 'smtp-address' => $email,
); );
@ -843,14 +850,16 @@ class rcube_kolab_contacts extends rcube_addressbook
$this->_connect(); $this->_connect();
// read contacts // read contacts
$this->contacts = array(); $this->contacts = $this->id2uid = array();
foreach ((array)$this->contactstorage->getObjects() as $record) { foreach ((array)$this->contactstorage->getObjects() as $record) {
// Because of a bug, sometimes group records are returned // Because of a bug, sometimes group records are returned
if ($record['__type'] == 'Group') if ($record['__type'] == 'Group')
continue; continue;
$contact = $this->_to_rcube_contact($record); $contact = $this->_to_rcube_contact($record);
$this->contacts[$contact['ID']] = $contact; $id = $contact['ID'];
$this->contacts[$id] = $contact;
$this->id2uid[$id] = $record['uid'];
} }
// sort data arrays according to desired list sorting // sort data arrays according to desired list sorting
@ -881,9 +890,9 @@ class rcube_kolab_contacts extends rcube_addressbook
// FIXME: folders without any distribution-list objects return contacts instead ?! // FIXME: folders without any distribution-list objects return contacts instead ?!
if ($record['__type'] != 'Group') if ($record['__type'] != 'Group')
continue; continue;
$record['ID'] = $record['uid']; $record['ID'] = md5($record['uid']);
foreach ((array)$record['member'] as $i => $member) { foreach ((array)$record['member'] as $i => $member) {
$mid = $member['uid']; $mid = md5($member['uid']);
$record['member'][$i]['ID'] = $mid; $record['member'][$i]['ID'] = $mid;
$this->groupmembers[$mid][] = $record['ID']; $this->groupmembers[$mid][] = $record['ID'];
} }
@ -899,7 +908,7 @@ class rcube_kolab_contacts extends rcube_addressbook
private function _to_rcube_contact($record) private function _to_rcube_contact($record)
{ {
$out = array( $out = array(
'ID' => $record['uid'], 'ID' => md5($record['uid']),
'email' => array(), 'email' => array(),
'phone' => array(), 'phone' => array(),
); );