Fix File support. Fix handling of non-inline attachments of event and file objects.

This commit is contained in:
Aleksander Machniak 2013-01-16 09:27:34 +01:00
parent f38105a809
commit ddeb606daf
11 changed files with 66 additions and 32 deletions

View file

@ -386,9 +386,11 @@ abstract class kolab_format
/**
* Convert the Kolab object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Kolab object data as hash array
*/
abstract public function to_array();
abstract public function to_array($data = array());
/**
* Callback for kolab_storage_cache to get object specific tags to cache

View file

@ -88,9 +88,11 @@ class kolab_format_configuration extends kolab_format
/**
* Convert the Configuration object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Config object data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))

View file

@ -266,9 +266,11 @@ class kolab_format_contact extends kolab_format
/**
* Convert the Contact object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Contact data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
@ -341,7 +343,7 @@ class kolab_format_contact extends kolab_format
if ($this->obj->photoMimetype())
$object['photo'] = $this->obj->photo();
else if ($this->xmlobject && ($photo_name = $this->xmlobject->pictureAttachmentName()))
$object['photo'] = $photo_name;
$object['photo'] = $photo_name;
// relateds -> spouse, children
$this->read_relateds($this->obj->relateds(), $object);

View file

@ -83,9 +83,11 @@ class kolab_format_distributionlist extends kolab_format
/**
* Convert the Distlist object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Distribution list data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))

View file

@ -106,9 +106,11 @@ class kolab_format_event extends kolab_format_xcal
/**
* Convert the Event object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Event data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
@ -158,8 +160,19 @@ class kolab_format_event extends kolab_format_xcal
}
}
$this->data = $object;
return $this->data;
// merge with additional data, e.g. attachments from the message
if ($data) {
foreach ($data as $idx => $value) {
if (is_array($value)) {
$object[$idx] = array_merge((array)$object[$idx], $value);
}
else {
$object[$idx] = $value;
}
}
}
return $this->data = $object;
}
/**

View file

@ -27,6 +27,7 @@ class kolab_format_file extends kolab_format
{
public $CTYPE = 'application/x-vnd.kolab.file';
protected $objclass = 'File';
protected $read_func = 'kolabformat::readKolabFile';
protected $write_func = 'kolabformat::writeKolabFile';
@ -36,12 +37,6 @@ class kolab_format_file extends kolab_format
'confidential' => kolabformat::ClassConfidential,
);
function __construct($xmldata = null)
{
$this->obj = new File;
$this->xmldata = $xmldata;
}
/**
* Set properties to the kolabformat object
*
@ -101,9 +96,11 @@ class kolab_format_file extends kolab_format
/**
* Convert the Configuration object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Config object data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
@ -123,12 +120,19 @@ class kolab_format_file extends kolab_format
'notes' => $this->obj->note(),
);
// attachments are mime message parts handled by kolab_storage_folder
// @TODO: handle inline attachments
// merge with additional data, e.g. attachments from the message
if ($data) {
foreach ($data as $idx => $value) {
if (is_array($value)) {
$object[$idx] = array_merge((array)$object[$idx], $value);
}
else {
$object[$idx] = $value;
}
}
}
$this->data = $object;
return $this->data;
return $this->data = $object;
}
/**
@ -155,6 +159,10 @@ class kolab_format_file extends kolab_format
public function get_words()
{
// Store filename in 'words' for fast access to file by name
if (empty($this->data['_attachments'])) {
return array();
}
$attachment = array_shift($this->data['_attachments']);
return array($attachment['name']);
}

View file

@ -66,9 +66,11 @@ class kolab_format_journal extends kolab_format
/**
* Convert the Configuration object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Config object data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
@ -83,7 +85,6 @@ class kolab_format_journal extends kolab_format
'changed' => self::php_datetime($this->obj->lastModified()),
);
// TODO: read object properties
$this->data = $object;

View file

@ -66,9 +66,11 @@ class kolab_format_note extends kolab_format
/**
* Convert the Configuration object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Config object data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
@ -83,7 +85,6 @@ class kolab_format_note extends kolab_format
'changed' => self::php_datetime($this->obj->lastModified()),
);
// TODO: read object properties
$this->data = $object;

View file

@ -71,9 +71,11 @@ class kolab_format_task extends kolab_format_xcal
/**
* Convert the Configuration object into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Config object data as hash array
*/
public function to_array()
public function to_array($data = array())
{
// return cached result
if (!empty($this->data))

View file

@ -88,9 +88,11 @@ abstract class kolab_format_xcal extends kolab_format
/**
* Convert common xcard properties into a hash array data structure
*
* @param array Additional data for merge
*
* @return array Object data as hash array
*/
public function to_array()
public function to_array($data = array())
{
$status_map = array_flip($this->status_map);
$sensitivity_map = array_flip($this->sensitivity_map);

View file

@ -524,11 +524,10 @@ class kolab_storage_folder
$format->load($xml);
if ($format->is_valid()) {
$object = $format->to_array();
$object['_type'] = $object_type;
$object['_msguid'] = $msguid;
$object['_mailbox'] = $this->name;
$object['_attachments'] = array_merge((array)$object['_attachments'], $attachments);
$object = $format->to_array(array('_attachments' => $attachments));
$object['_type'] = $object_type;
$object['_msguid'] = $msguid;
$object['_mailbox'] = $this->name;
$object['_formatobj'] = $format;
return $object;
@ -766,7 +765,7 @@ class kolab_storage_folder
$object['uid'] = $format->uid; // read UID from format
$object['_formatobj'] = $format;
if (!$format->is_valid() || empty($object['uid'])) {
if (empty($xml) || !$format->is_valid() || empty($object['uid'])) {
return false;
}