storeAttachment() public method

Store an attachment.
public storeAttachment ( string $data_id, string $obid, string $attachment_id, resource $data )
$data_id string ID of the data set.
$obid string Object backend id.
$attachment_id string Attachment ID.
$data resource A stream opened to the attachment data.
Exemplo n.º 1
0
Arquivo: Data.php Projeto: Gomez/horde
 /**
  * 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();
 }
Exemplo n.º 2
0
 /**
  * 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];
             // 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();
 }