Horde_Kolab_Storage_Cache_Data::store PHP Method

store() public method

Stores the objects list in the cache.
public store ( array $objects, Horde_Kolab_Storage_Folder_Stamp $stamp, string $version, array $delete = [] )
$objects array
$stamp Horde_Kolab_Storage_Folder_Stamp The current stamp.
$version string The format version of the provided data.
$delete array 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];
                // Check if the delete request is for the last version of an object.
                // Otherwise the removal of a duplicate might remove the
                // current version of an object.
                $cached_obid = $this->_data[self::O2B][$object_id];
                if ($cached_obid == $obid) {
                    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]);
                } else {
                    Horde::log(sprintf("[KOLAB_STORAGE] Keeping object %s" . " with uid %d, duplicate object with uid %d was removed", $object_id, $cached_obid, $obid), 'DEBUG');
                }
                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();
    }

Usage Example

Example #1
0
 /**
  * Perform a complete synchronization.
  *
  * @param Horde_Kolab_Storage_Folder_Stamp $stamp The current stamp.
  * @param array $params Additional parameters.
  *
  * @return NULL
  */
 private function _completeSynchronization(Horde_Kolab_Storage_Folder_Stamp $stamp, $params = array())
 {
     $this->_data_cache->reset();
     $ids = $stamp->ids();
     $params['last_sync'] = false;
     $params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED] = empty($ids) ? array() : $this->fetch($ids);
     $this->_data_cache->store($params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED], $stamp, $this->getVersion());
     $params['current_sync'] = $this->_data_cache->getLastSync();
     parent::synchronize($params);
     $this->_data_cache->save();
 }
All Usage Examples Of Horde_Kolab_Storage_Cache_Data::store