From ab69f4909165d20fcf09cb1d361370a26c6ad987 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 15 May 2012 19:05:46 +0200 Subject: [PATCH] Prepare for fulltext indexing in kolab_storage_cache; fix saving contacts with no address data (#769) --- plugins/libkolab/lib/kolab_format.php | 20 ++++++++++++++++++ plugins/libkolab/lib/kolab_format_contact.php | 21 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php index 134df856..4c8e363b 100644 --- a/plugins/libkolab/lib/kolab_format.php +++ b/plugins/libkolab/lib/kolab_format.php @@ -232,4 +232,24 @@ abstract class kolab_format * @param array Hash array with object properties (produced by Horde Kolab_Format classes) */ abstract public function fromkolab2($object); + + /** + * Callback for kolab_storage_cache to get object specific tags to cache + * + * @return array List of tags to save in cache + */ + public function get_tags() + { + return array(); + } + + /** + * 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() + { + return array(); + } } diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php index 59a6e0a0..646f6ca7 100644 --- a/plugins/libkolab/lib/kolab_format_contact.php +++ b/plugins/libkolab/lib/kolab_format_contact.php @@ -26,6 +26,8 @@ class kolab_format_contact extends kolab_format { public $CTYPE = 'application/vcard+xml'; + public static $fulltext_cols = array('name', 'firstname', 'surname', 'middlename', 'email'); + public $phonetypes = array( 'home' => Telephone::Home, 'work' => Telephone::Work, @@ -207,7 +209,7 @@ class kolab_format_contact extends kolab_format // addresses $adrs = new vectoraddress; - foreach ($object['address'] as $address) { + foreach ((array)$object['address'] as $address) { $adr = new Address; $type = $this->addresstypes[$address['type']]; if (isset($type)) @@ -416,6 +418,23 @@ class kolab_format_contact extends kolab_format return $this->data; } + /** + * 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() + { + $data = ''; + foreach (self::$fulltext_cols as $col) { + $val = is_array($this->data[$col]) ? join(" ", $this->data[$col]) : $this->data[$col]; + if (strlen($val)) + $data .= $val . ' '; + } + + return array_unique(rcube_utils::normalize_string($data, true)); + } + /** * Load data from old Kolab2 format *