diff --git a/plugins/libkolab/SQL/mysql.initial.sql b/plugins/libkolab/SQL/mysql.initial.sql index 8603bc89..764da2af 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 00000000..76577e6e --- /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 809fb29c..66ba3801 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 5e64e307..104d90fe 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 cde02880..3676f053 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 d25bd473..0110e4ef 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 ec97767c..a32f40c5 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 191c7fe8..3fffa89a 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 3528d162..b9a1b4fb 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 cee6345b..466c5362 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 0fa28065..56f22dc0 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 95f07182..92491557 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 ef4dd224..ff8c2760 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('!()[\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('!()[\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 69b2b6f1..cd3e3a02 100644 --- a/plugins/libkolab/package.xml +++ b/plugins/libkolab/package.xml @@ -19,10 +19,10 @@ machniak@kolabsys.com yes - 2012-11-21 + 2013-04-19 - 0.9-beta - 0.9-beta + 0.9 + 0.9 stable @@ -83,6 +83,7 @@ +