From 18d9a7f508d0bb93b564688dcaa3fbe76d53ca90 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 20 Jul 2011 15:38:34 +0200 Subject: [PATCH] Convert kolab contacts into Roundcube internal format as late as possible --- .../lib/rcube_kolab_contacts.php | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index b4c72a4f..807eae45 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -283,7 +283,7 @@ class rcube_kolab_contacts extends rcube_addressbook for ($i = $start_row; $i < $last_row; $i++) { if ($id = $ids[$i]) - $this->result->add($this->contacts[$id]); + $this->result->add($this->_fetch_record($id)); } return $this->result; @@ -345,6 +345,8 @@ class rcube_kolab_contacts extends rcube_addressbook // search be iterating over all records in memory foreach ($this->contacts as $id => $contact) { + $contact = $this->_fetch_record($id); + // check if current contact has required values, otherwise skip it if ($required) { foreach ($required as $f) @@ -440,7 +442,7 @@ class rcube_kolab_contacts extends rcube_addressbook $this->_fetch_contacts(); if ($this->contacts[$id]) { $this->result = new rcube_result_set(1); - $this->result->add($this->contacts[$id]); + $this->result->add($this->_fetch_record($id)); return $assoc ? $this->contacts[$id] : $this->result; } @@ -815,7 +817,7 @@ class rcube_kolab_contacts extends rcube_addressbook foreach ($ids as $contact_id) { if ($uid = $this->id2uid[$contact_id]) { - $contact = $this->contacts[$contact_id]; + $contact = $this->_fetch_record($contact_id); foreach ($this->get_col_values('email', $contact, true) as $email) { $list['member'][] = array( 'uid' => $uid, @@ -930,9 +932,9 @@ class rcube_kolab_contacts extends rcube_addressbook if ($record['__type'] == 'Group') continue; - $contact = $this->_to_rcube_contact($record); - $id = $contact['ID']; - $this->contacts[$id] = $contact; + // only create a meta record in $this->contacts to save resouces + $id = md5($record['uid']); + $this->contacts[$id] = array('uid' => $record['uid'], 'name' => $record['full-name'], '_meta' => true); $this->id2uid[$id] = $record['uid']; } @@ -942,6 +944,22 @@ class rcube_kolab_contacts extends rcube_addressbook } + /** + * Fetch the entire contact object from storage + * and convert it into Roundcube internal format + */ + private function _fetch_record($id) + { + // replace meta record with a full copy of the contact + if ($this->contacts[$id] && $this->contacts[$id]['_meta']) { + if ($record = $this->contactstorage->getObject($this->contacts[$id]['uid'])) + $this->contacts[$id] = $this->_to_rcube_contact($record); + } + + return $this->contacts[$id]; + } + + /** * Callback function for sorting contacts */