Implemented new method of storing filename and mimetype of file objects
This commit is contained in:
parent
08332b5238
commit
e03156fc1f
14 changed files with 65 additions and 74 deletions
|
@ -21,7 +21,9 @@ CREATE TABLE `kolab_cache` (
|
|||
`dtend` DATETIME,
|
||||
`tags` VARCHAR(255) NOT NULL,
|
||||
`words` TEXT NOT NULL,
|
||||
PRIMARY KEY(`resource`,`type`,`msguid`)
|
||||
`filename` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY(`resource`,`type`,`msguid`),
|
||||
INDEX `resource_filename` (`resource`, `filename`)
|
||||
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||
|
||||
INSERT INTO `system` (`name`, `value`) VALUES ('libkolab-version', '2013011000');
|
||||
INSERT INTO `system` (`name`, `value`) VALUES ('libkolab-version', '2013041900');
|
||||
|
|
3
plugins/libkolab/SQL/mysql/2013041900.sql
Normal file
3
plugins/libkolab/SQL/mysql/2013041900.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
DELETE FROM `kolab_cache` WHERE `type` = 'file';
|
||||
ALTER TABLE `kolab_cache` ADD `filename` varchar(255) DEFAULT NULL;
|
||||
ALTER TABLE `kolab_cache` ADD INDEX `resource_filename` (`resource`, `filename`);
|
|
@ -438,6 +438,18 @@ abstract class kolab_format
|
|||
$object['x-custom'][] = array($cp->identifier, $cp->value);
|
||||
}
|
||||
|
||||
// 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 $object;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,16 +98,12 @@ class kolab_format_configuration extends kolab_format
|
|||
if (!empty($this->data))
|
||||
return $this->data;
|
||||
|
||||
$this->init();
|
||||
// read common object props into local data object
|
||||
$object = parent::to_array($data);
|
||||
|
||||
$type_map = array_flip($this->type_map);
|
||||
|
||||
// read object properties
|
||||
$object = array(
|
||||
'uid' => $this->obj->uid(),
|
||||
'created' => self::php_datetime($this->obj->created()),
|
||||
'changed' => self::php_datetime($this->obj->lastModified()),
|
||||
'type' => $type_map[$this->obj->type()],
|
||||
);
|
||||
$object['type'] = $type_map[$this->obj->type()];
|
||||
|
||||
// read type-specific properties
|
||||
switch ($object['type']) {
|
||||
|
|
|
@ -266,7 +266,7 @@ class kolab_format_contact extends kolab_format
|
|||
return $this->data;
|
||||
|
||||
// read common object props into local data object
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
$object['name'] = $this->obj->name();
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class kolab_format_distributionlist extends kolab_format
|
|||
return $this->data;
|
||||
|
||||
// read common object props into local data object
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
// add object properties
|
||||
$object += array(
|
||||
|
|
|
@ -147,7 +147,7 @@ class kolab_format_event extends kolab_format_xcal
|
|||
return $this->data;
|
||||
|
||||
// read common xcal props
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
// read object properties
|
||||
$object += array(
|
||||
|
@ -178,12 +178,12 @@ class kolab_format_event extends kolab_format_xcal
|
|||
// skip cid: attachments which are mime message parts handled by kolab_storage_folder
|
||||
if (substr($attach->uri(), 0, 4) != 'cid:' && $attach->label()) {
|
||||
$name = $attach->label();
|
||||
$data = $attach->data();
|
||||
$content = $attach->data();
|
||||
$object['_attachments'][$name] = array(
|
||||
'name' => $name,
|
||||
'mimetype' => $attach->mimetype(),
|
||||
'size' => strlen($data),
|
||||
'content' => $data,
|
||||
'size' => strlen($content),
|
||||
'content' => $content,
|
||||
);
|
||||
}
|
||||
else if (substr($attach->uri(), 0, 4) == 'http') {
|
||||
|
@ -207,18 +207,6 @@ class kolab_format_event extends kolab_format_xcal
|
|||
$object['thisandfuture'] = $this->obj->thisAndFuture();
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,11 +98,12 @@ class kolab_format_file extends kolab_format
|
|||
public function to_array($data = array())
|
||||
{
|
||||
// return cached result
|
||||
if (!empty($this->data))
|
||||
if (!empty($this->data)) {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
// read common object props into local data object
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
$sensitivity_map = array_flip($this->sensitivity_map);
|
||||
|
||||
|
@ -113,18 +114,6 @@ class kolab_format_file extends kolab_format
|
|||
'notes' => $this->obj->note(),
|
||||
);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -141,22 +130,14 @@ class kolab_format_file extends kolab_format
|
|||
$tags[] = rcube_utils::normalize_string($cat);
|
||||
}
|
||||
|
||||
// Add file mimetype to tags
|
||||
if (!empty($this->data['_attachments'])) {
|
||||
$attachment = array_shift($this->data['_attachments']);
|
||||
if ($attachment['mimetype']) {
|
||||
$tags[] = $attachment['mimetype'];
|
||||
}
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for kolab_storage_cache to get words to index for fulltext search
|
||||
*
|
||||
* @return array List of words to save in cache
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ class kolab_format_journal extends kolab_format
|
|||
return $this->data;
|
||||
|
||||
// read common object props into local data object
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
// TODO: read object properties
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class kolab_format_note extends kolab_format
|
|||
return $this->data;
|
||||
|
||||
// read common object props into local data object
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
// TODO: read object properties
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class kolab_format_task extends kolab_format_xcal
|
|||
return $this->data;
|
||||
|
||||
// read common xcal props
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
$object['complete'] = intval($this->obj->percentComplete());
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class kolab_format_xcal extends kolab_format
|
|||
public function to_array($data = array())
|
||||
{
|
||||
// read common object props
|
||||
$object = parent::to_array();
|
||||
$object = parent::to_array($data);
|
||||
|
||||
$status_map = array_flip($this->status_map);
|
||||
$sensitivity_map = array_flip($this->sensitivity_map);
|
||||
|
|
|
@ -238,8 +238,8 @@ class kolab_storage_cache
|
|||
|
||||
$result = $this->db->query(
|
||||
"INSERT INTO kolab_cache ".
|
||||
" (resource, type, msguid, uid, created, changed, data, xml, dtstart, dtend, tags, words)".
|
||||
" VALUES (?, ?, ?, ?, " . $this->db->now() . ", ?, ?, ?, ?, ?, ?, ?)",
|
||||
" (resource, type, msguid, uid, created, changed, data, xml, dtstart, dtend, tags, words, filename)".
|
||||
" VALUES (?, ?, ?, ?, " . $this->db->now() . ", ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
$this->resource_uri,
|
||||
$objtype,
|
||||
$msguid,
|
||||
|
@ -250,7 +250,8 @@ class kolab_storage_cache
|
|||
$sql_data['dtstart'],
|
||||
$sql_data['dtend'],
|
||||
$sql_data['tags'],
|
||||
$sql_data['words']
|
||||
$sql_data['words'],
|
||||
$sql_data['filename']
|
||||
);
|
||||
|
||||
if (!$this->db->affected_rows($result)) {
|
||||
|
@ -537,6 +538,12 @@ class kolab_storage_cache
|
|||
if ($object['due'])
|
||||
$sql_data['dtend'] = date('Y-m-d H:i:s', is_object($object['due']) ? $object['due']->format('U') : $object['due']);
|
||||
}
|
||||
else if ($objtype == 'file') {
|
||||
if (!empty($object['_attachments'])) {
|
||||
reset($object['_attachments']);
|
||||
$sql_data['filename'] = $object['_attachments'][key($object['_attachments'])]['name'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($object['changed']) {
|
||||
$sql_data['changed'] = date('Y-m-d H:i:s', is_object($object['changed']) ? $object['changed']->format('U') : $object['changed']);
|
||||
|
@ -625,6 +632,7 @@ class kolab_storage_cache
|
|||
$this->db->quote($sql_data['dtend']),
|
||||
$this->db->quote($sql_data['tags']),
|
||||
$this->db->quote($sql_data['words']),
|
||||
$this->db->quote($sql_data['filename']),
|
||||
);
|
||||
$line = '(' . join(',', $values) . ')';
|
||||
}
|
||||
|
@ -632,7 +640,7 @@ class kolab_storage_cache
|
|||
if ($buffer && (!$msguid || (strlen($buffer) + strlen($line) > $this->max_sql_packet))) {
|
||||
$result = $this->db->query(
|
||||
"INSERT INTO kolab_cache ".
|
||||
" (resource, type, msguid, uid, created, changed, data, xml, dtstart, dtend, tags, words)".
|
||||
" (resource, type, msguid, uid, created, changed, data, xml, dtstart, dtend, tags, words, filename)".
|
||||
" VALUES $buffer"
|
||||
);
|
||||
if (!$this->db->affected_rows($result)) {
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
<email>machniak@kolabsys.com</email>
|
||||
<active>yes</active>
|
||||
</developer>
|
||||
<date>2012-11-21</date>
|
||||
<date>2013-04-19</date>
|
||||
<version>
|
||||
<release>0.9-beta</release>
|
||||
<api>0.9-beta</api>
|
||||
<release>0.9</release>
|
||||
<api>0.9</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
|
@ -83,6 +83,7 @@
|
|||
<file name="config.inc.php.dist" role="data"></file>
|
||||
<file name="LICENSE" role="data"></file>
|
||||
<file name="README" role="data"></file>
|
||||
<file name="UPGRADING" role="data"></file>
|
||||
</dir>
|
||||
<!-- / -->
|
||||
</contents>
|
||||
|
|
Loading…
Add table
Reference in a new issue