Prepare for fulltext indexing in kolab_storage_cache; fix saving contacts with no address data (#769)

This commit is contained in:
Thomas Bruederli 2012-05-15 19:05:46 +02:00
parent d9924e675d
commit ab69f49091
2 changed files with 40 additions and 1 deletions

View file

@ -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();
}
}

View file

@ -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
*