/**
* Stores the objects list in the cache.
*
* @param array $object The object data to store.
* @param Horde_Kolab_Storage_Folder_Stamp $stamp The current stamp.
* @param string $version The format version of
* the provided data.
* @param array $delete Backend IDs that were
* removed.
*/
public function store(array $objects, Horde_Kolab_Storage_Folder_Stamp $stamp, $version, array $delete = array())
{
$this->_load();
if (!empty($delete)) {
foreach ($delete as $obid => $object_id) {
$object = $this->_data[self::OBJECTS][$object_id];
if (!empty($object['_attachments'])) {
// @todo clean up attachment formatting mess.
if (isset($object['_attachments']['id'])) {
$ids = $object['_attachments']['id'];
} else {
$ids = array_keys($object['_attachments']);
}
foreach ($ids as $id) {
$this->_cache->deleteAttachment($this->getDataId(), $obid, $id);
}
}
unset($this->_data[self::O2B][$object_id]);
unset($this->_data[self::OBJECTS][$object_id]);
unset($this->_data[self::B2O][$obid]);
}
}
foreach ($objects as $obid => $object) {
if (!empty($object) && isset($object['uid'])) {
if (isset($this->_data[self::O2B][$object['uid']])) {
if (!isset($this->_data[self::DUPLICATES][$object['uid']])) {
$this->_data[self::DUPLICATES][$object['uid']][] = $this->_data[self::O2B][$object['uid']];
}
$this->_data[self::DUPLICATES][$object['uid']][] = $obid;
}
$this->_data[self::B2O][$obid] = $object['uid'];
$this->_data[self::O2B][$object['uid']] = $obid;
if (isset($object['_attachments'])) {
$attachments = array();
foreach ($object['_attachments'] as $id => $attachment) {
$attachments['id'][] = $id;
if (isset($attachment['name'])) {
$attachments['name'][$attachment['name']][] = $id;
}
if (isset($attachment['type'])) {
$attachments['type'][$attachment['type']][] = $id;
}
$this->_cache->storeAttachment($this->getDataId(), $obid, $id, $attachment['content']);
}
$object['_attachments'] = $attachments;
}
$this->_data[self::OBJECTS][$object['uid']] = $object;
} else {
$this->_data[self::B2O][$obid] = false;
$this->_data[self::ERRORS][] = $obid;
}
}
$this->_data[self::QUERIES] = array();
$this->_data[self::STAMP] = serialize($stamp);
$this->_data[self::DATA_VERSION] = $version;
$this->_data[self::VERSION] = self::FORMAT_VERSION;
$this->_data[self::ID] = serialize($this->_parameters);
$this->_data[self::SYNC] = time();
}