summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2013-04-19 12:20:55 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2013-04-19 12:20:55 (GMT)
commite03156fc1f03c9968915c31aa63cfdcd5b5099d9 (patch)
treea07bdd5381e03be59a9e98b890df2e97af429f41
parent08332b5238d4fa0357c3e24cc18c2287c3a18954 (diff)
downloadroundcubemail-plugins-kolab-e03156fc1f03c9968915c31aa63cfdcd5b5099d9.tar.gz
Implemented new method of storing filename and mimetype of file objects
-rw-r--r--plugins/libkolab/SQL/mysql.initial.sql6
-rw-r--r--plugins/libkolab/SQL/mysql/2013041900.sql3
-rw-r--r--plugins/libkolab/lib/kolab_format.php12
-rw-r--r--plugins/libkolab/lib/kolab_format_configuration.php12
-rw-r--r--plugins/libkolab/lib/kolab_format_contact.php2
-rw-r--r--plugins/libkolab/lib/kolab_format_distributionlist.php2
-rw-r--r--plugins/libkolab/lib/kolab_format_event.php22
-rw-r--r--plugins/libkolab/lib/kolab_format_file.php39
-rw-r--r--plugins/libkolab/lib/kolab_format_journal.php2
-rw-r--r--plugins/libkolab/lib/kolab_format_note.php2
-rw-r--r--plugins/libkolab/lib/kolab_format_task.php2
-rw-r--r--plugins/libkolab/lib/kolab_format_xcal.php2
-rw-r--r--plugins/libkolab/lib/kolab_storage_cache.php26
-rw-r--r--plugins/libkolab/package.xml7
14 files changed, 65 insertions, 74 deletions
diff --git a/plugins/libkolab/SQL/mysql.initial.sql b/plugins/libkolab/SQL/mysql.initial.sql
index 8603bc8..764da2a 100644
--- a/plugins/libkolab/SQL/mysql.initial.sql
+++ b/plugins/libkolab/SQL/mysql.initial.sql
@@ -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');
diff --git a/plugins/libkolab/SQL/mysql/2013041900.sql b/plugins/libkolab/SQL/mysql/2013041900.sql
new file mode 100644
index 0000000..76577e6
--- /dev/null
+++ b/plugins/libkolab/SQL/mysql/2013041900.sql
@@ -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`);
diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index 809fb29..66ba380 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -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;
}
diff --git a/plugins/libkolab/lib/kolab_format_configuration.php b/plugins/libkolab/lib/kolab_format_configuration.php
index 5e64e30..104d90f 100644
--- a/plugins/libkolab/lib/kolab_format_configuration.php
+++ b/plugins/libkolab/lib/kolab_format_configuration.php
@@ -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']) {
diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index cde0288..3676f05 100644
--- a/plugins/libkolab/lib/kolab_format_contact.php
+++ b/plugins/libkolab/lib/kolab_format_contact.php
@@ -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();
diff --git a/plugins/libkolab/lib/kolab_format_distributionlist.php b/plugins/libkolab/lib/kolab_format_distributionlist.php
index d25bd47..0110e4e 100644
--- a/plugins/libkolab/lib/kolab_format_distributionlist.php
+++ b/plugins/libkolab/lib/kolab_format_distributionlist.php
@@ -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(
diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php
index ec97767..a32f40c 100644
--- a/plugins/libkolab/lib/kolab_format_event.php
+++ b/plugins/libkolab/lib/kolab_format_event.php
@@ -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(
@@ -177,13 +177,13 @@ 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();
+ $name = $attach->label();
+ $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;
}
diff --git a/plugins/libkolab/lib/kolab_format_file.php b/plugins/libkolab/lib/kolab_format_file.php
index 191c7fe..3fffa89 100644
--- a/plugins/libkolab/lib/kolab_format_file.php
+++ b/plugins/libkolab/lib/kolab_format_file.php
@@ -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);
}
- 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();
+ // Add file mimetype to tags
+ if (!empty($this->data['_attachments'])) {
+ $attachment = array_shift($this->data['_attachments']);
+ if ($attachment['mimetype']) {
+ $tags[] = $attachment['mimetype'];
+ }
}
- $attachment = array_shift($this->data['_attachments']);
- return array($attachment['name']);
+ return $tags;
}
}
diff --git a/plugins/libkolab/lib/kolab_format_journal.php b/plugins/libkolab/lib/kolab_format_journal.php
index 3528d16..b9a1b4f 100644
--- a/plugins/libkolab/lib/kolab_format_journal.php
+++ b/plugins/libkolab/lib/kolab_format_journal.php
@@ -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
diff --git a/plugins/libkolab/lib/kolab_format_note.php b/plugins/libkolab/lib/kolab_format_note.php
index cee6345..466c536 100644
--- a/plugins/libkolab/lib/kolab_format_note.php
+++ b/plugins/libkolab/lib/kolab_format_note.php
@@ -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
diff --git a/plugins/libkolab/lib/kolab_format_task.php b/plugins/libkolab/lib/kolab_format_task.php
index 0fa2806..56f22dc 100644
--- a/plugins/libkolab/lib/kolab_format_task.php
+++ b/plugins/libkolab/lib/kolab_format_task.php
@@ -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());
diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php
index 95f0718..9249155 100644
--- a/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/plugins/libkolab/lib/kolab_format_xcal.php
@@ -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);
diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index ef4dd22..ff8c276 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -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)) {
@@ -515,9 +516,9 @@ class kolab_storage_cache
*/
private function _serialize($object)
{
- $bincols = array_flip($this->binary_cols);
+ $bincols = array_flip($this->binary_cols);
$sql_data = array('changed' => null, 'dtstart' => null, 'dtend' => null, 'xml' => '', 'tags' => '', 'words' => '');
- $objtype = $object['_type'] ? $object['_type'] : $this->folder->type;
+ $objtype = $object['_type'] ? $object['_type'] : $this->folder->type;
// set type specific values
if ($objtype == 'event') {
@@ -537,14 +538,20 @@ 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']);
}
if ($object['_formatobj']) {
- $sql_data['xml'] = preg_replace('!(</?[a-z0-9:-]+>)[\n\r\t\s]+!ms', '$1', (string)$object['_formatobj']->write(3.0));
- $sql_data['tags'] = ' ' . join(' ', $object['_formatobj']->get_tags()) . ' '; // pad with spaces for strict/prefix search
+ $sql_data['xml'] = preg_replace('!(</?[a-z0-9:-]+>)[\n\r\t\s]+!ms', '$1', (string)$object['_formatobj']->write(3.0));
+ $sql_data['tags'] = ' ' . join(' ', $object['_formatobj']->get_tags()) . ' '; // pad with spaces for strict/prefix search
$sql_data['words'] = ' ' . join(' ', $object['_formatobj']->get_words()) . ' ';
}
@@ -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)) {
@@ -728,7 +736,7 @@ class kolab_storage_cache
if (!isset($this->uid2msg[$uid])) {
// use IMAP SEARCH to get the right message
$index = $this->imap->search_once($this->folder->name, ($deleted ? '' : 'UNDELETED ') .
- 'HEADER SUBJECT ' . rcube_imap_generic::escape($uid));
+ 'HEADER SUBJECT ' . rcube_imap_generic::escape($uid));
$results = $index->get();
$this->uid2msg[$uid] = $results[0];
}
diff --git a/plugins/libkolab/package.xml b/plugins/libkolab/package.xml
index 69b2b6f..cd3e3a0 100644
--- a/plugins/libkolab/package.xml
+++ b/plugins/libkolab/package.xml
@@ -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>