2 commits - plugins/kolab_addressbook

Aleksander Machniak machniak at kolabsys.com
Wed Aug 7 12:35:58 CEST 2013


 plugins/kolab_addressbook/lib/rcube_kolab_contacts.php |   58 ++++++++++++-----
 1 file changed, 42 insertions(+), 16 deletions(-)

New commits:
commit d6149c398d0882c437215b9f2d0af1e3e03b4f94
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Wed Aug 7 12:34:37 2013 +0200

    Fixed conversion of contact date to kolab format (Bug #2094)
    - Add contact in Roundcube created contacts with no email address.

diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
index dd58fdd..b0096c4 100644
--- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
+++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
@@ -1142,8 +1142,9 @@ class rcube_kolab_contacts extends rcube_addressbook
 
         // convert email, website, phone values
         foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) {
+            $col_values = $this->get_col_values($col, $contact);
             $contact[$col] = array();
-            foreach ($this->get_col_values($col, $contact) as $type => $values) {
+            foreach ($col_values as $type => $values) {
                 foreach ((array)$values as $val) {
                     if (!empty($val)) {
                         $contact[$col][] = array($propname => $val, 'type' => $type);


commit 60778eed8b9092d0dfb978cc00d410ee9019b66e
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Wed Aug 7 12:30:54 2013 +0200

    Fix handling of composite field names (e.g. email:address) in fulltext
    fields and required fields when searching contacts (Bug #2095)

diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
index dd08775..dd58fdd 100644
--- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
+++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
@@ -377,19 +377,7 @@ class rcube_kolab_contacts extends rcube_addressbook
 
         // pass query to storage if only indexed cols are involved
         // NOTE: this is only some rough pre-filtering but probably includes false positives
-        $squery = array();
-        if (count(array_intersect(kolab_format_contact::$fulltext_cols, $fields)) == $scount) {
-            switch ($mode) {
-                case 1:  $prefix = '^'; $suffix = '$'; break;  // strict
-                case 2:  $prefix = '^'; $suffix = '';  break;  // prefix
-                default: $prefix = '';  $suffix = '';  break;  // substring
-            }
-
-            $search_string = is_array($value) ? join(' ', $value) : $value;
-            foreach (rcube_utils::normalize_string($search_string, true) as $word) {
-                $squery[] = array('words', 'LIKE', $prefix . $word . $suffix);
-            }
-        }
+        $squery = $this->_search_query($fields, $value, $mode);
 
         // get all/matching records
         $this->_fetch_contacts($squery);
@@ -401,9 +389,12 @@ class rcube_kolab_contacts extends rcube_addressbook
         foreach ($this->contacts as $id => $contact) {
             // check if current contact has required values, otherwise skip it
             if ($required) {
-                foreach ($required as $f)
-                    if (empty($contact[$f]))
+                foreach ($required as $f) {
+                    // required field might be 'email', but contact might contain 'email:home'
+                    if (!($v = rcube_addressbook::get_col_values($f, $contact, true)) || empty($v)) {
                         continue 2;
+                    }
+                }
             }
 
             $found = array();
@@ -1050,6 +1041,40 @@ class rcube_kolab_contacts extends rcube_addressbook
     }
 
     /**
+     * Build SQL query for fulltext matches
+     */
+    private function _search_query($fields, $value, $mode)
+    {
+        $query = array();
+        $cols  = array();
+
+        // $fulltext_cols might contain composite field names e.g. 'email:address' while $fields not
+        foreach (kolab_format_contact::$fulltext_cols as $col) {
+            if ($pos = strpos($col, ':')) {
+                $col = substr($col, 0, $pos);
+            }
+            if (in_array($col, $fields)) {
+                $cols[] = $col;
+            }
+        }
+
+        if (count($cols) == count($fields)) {
+            switch ($mode) {
+                case 1:  $prefix = '^'; $suffix = '$'; break;  // strict
+                case 2:  $prefix = '^'; $suffix = '';  break;  // prefix
+                default: $prefix = '';  $suffix = '';  break;  // substring
+            }
+
+            $search_string = is_array($value) ? join(' ', $value) : $value;
+            foreach (rcube_utils::normalize_string($search_string, true) as $word) {
+                $query[] = array('words', 'LIKE', $prefix . $word . $suffix);
+            }
+        }
+
+        return $query;
+    }
+
+    /**
      * Map fields from internal Kolab_Format to Roundcube contact format
      */
     private function _to_rcube_contact($record)




More information about the commits mailing list