Convert kolab contacts into Roundcube internal format as late as possible

This commit is contained in:
Thomas Bruederli 2011-07-20 15:38:34 +02:00
parent 1b9a25e84d
commit 18d9a7f508

View file

@ -283,7 +283,7 @@ class rcube_kolab_contacts extends rcube_addressbook
for ($i = $start_row; $i < $last_row; $i++) { for ($i = $start_row; $i < $last_row; $i++) {
if ($id = $ids[$i]) if ($id = $ids[$i])
$this->result->add($this->contacts[$id]); $this->result->add($this->_fetch_record($id));
} }
return $this->result; return $this->result;
@ -345,6 +345,8 @@ class rcube_kolab_contacts extends rcube_addressbook
// search be iterating over all records in memory // search be iterating over all records in memory
foreach ($this->contacts as $id => $contact) { foreach ($this->contacts as $id => $contact) {
$contact = $this->_fetch_record($id);
// check if current contact has required values, otherwise skip it // check if current contact has required values, otherwise skip it
if ($required) { if ($required) {
foreach ($required as $f) foreach ($required as $f)
@ -440,7 +442,7 @@ class rcube_kolab_contacts extends rcube_addressbook
$this->_fetch_contacts(); $this->_fetch_contacts();
if ($this->contacts[$id]) { if ($this->contacts[$id]) {
$this->result = new rcube_result_set(1); $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; return $assoc ? $this->contacts[$id] : $this->result;
} }
@ -815,7 +817,7 @@ class rcube_kolab_contacts extends rcube_addressbook
foreach ($ids as $contact_id) { foreach ($ids as $contact_id) {
if ($uid = $this->id2uid[$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) { foreach ($this->get_col_values('email', $contact, true) as $email) {
$list['member'][] = array( $list['member'][] = array(
'uid' => $uid, 'uid' => $uid,
@ -930,9 +932,9 @@ class rcube_kolab_contacts extends rcube_addressbook
if ($record['__type'] == 'Group') if ($record['__type'] == 'Group')
continue; continue;
$contact = $this->_to_rcube_contact($record); // only create a meta record in $this->contacts to save resouces
$id = $contact['ID']; $id = md5($record['uid']);
$this->contacts[$id] = $contact; $this->contacts[$id] = array('uid' => $record['uid'], 'name' => $record['full-name'], '_meta' => true);
$this->id2uid[$id] = $record['uid']; $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 * Callback function for sorting contacts
*/ */