2 commits - plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Wed Jun 20 18:47:16 CEST 2012


 plugins/libkolab/lib/kolab_storage_cache.php  |   50 ++++++++++++++++++++++----
 plugins/libkolab/lib/kolab_storage_folder.php |   35 +++++++++++++++---
 plugins/libkolab/libkolab.php                 |    2 -
 3 files changed, 75 insertions(+), 12 deletions(-)

New commits:
commit 078b953953f88948f6a0c656f2b78b4cd69ca2b6
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Jun 20 18:47:01 2012 +0200

    Add getter for a list of object UIDs (#848)

diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index 84841d0..4e3846d 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -297,23 +297,29 @@ class kolab_storage_cache
      *
      * @param array Pseudo-SQL query as list of filter parameter triplets
      *   triplet: array('<colname>', '<comparator>', '<value>')
-     * @return array List of Kolab data objects (each represented as hash array)
+     * @param boolean Set true to only return UIDs instead of complete objects
+     * @return array List of Kolab data objects (each represented as hash array) or UIDs
      */
-    public function select($query = array())
+    public function select($query = array(), $uids = false)
     {
         $result = array();
 
         // read from local cache DB (assume it to be synchronized)
         if ($this->ready) {
             $sql_result = $this->db->query(
-                "SELECT * FROM kolab_cache ".
+                "SELECT " . ($uids ? 'msguid, uid' : '*') . " FROM kolab_cache ".
                 "WHERE resource=? " . $this->_sql_where($query),
                 $this->resource_uri
             );
 
             while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
-                if ($object = $this->_unserialize($sql_arr))
+                if ($uids) {
+                    $this->uid2msg[$sql_arr['uid']] = $sql_arr['msguid'];
+                    $result[] = $sql_arr['uid'];
+                }
+                else if ($object = $this->_unserialize($sql_arr)) {
                     $result[] = $object;
+                }
             }
         }
         else {
@@ -330,7 +336,7 @@ class kolab_storage_cache
             }
 
             // fetch all messages in $index from IMAP
-            $result = $this->_fetch($index, $filter['type']);
+            $result = $uids ? $this->_fetch_uids($index, $filter['type']) : $this->_fetch($index, $filter['type']);
 
             // TODO: post-filter result according to query
         }
@@ -424,7 +430,9 @@ class kolab_storage_cache
     /**
      * Fetch messages from IMAP
      *
-     * @param array List of message UIDs to fetch
+     * @param array  List of message UIDs to fetch
+     * @param string Requested object type or * for all
+     * @param string IMAP folder to read from
      * @return array List of parsed Kolab objects
      */
     private function _fetch($index, $type = null, $folder = null)
@@ -442,6 +450,36 @@ class kolab_storage_cache
 
 
     /**
+     * Fetch object UIDs (aka message subjects) from IMAP
+     *
+     * @param array List of message UIDs to fetch
+     * @param string Requested object type or * for all
+     * @param string IMAP folder to read from
+     * @return array List of parsed Kolab objects
+     */
+    private function _fetch_uids($index, $type = null)
+    {
+        if (!$type)
+            $type = $this->folder->type;
+
+        $results = array();
+        foreach ((array)$this->imap->fetch_headers($this->folder->name, $index, false) as $msguid => $headers) {
+            $object_type = preg_replace('/dictionary.[a-z]+$/', 'dictionary', substr($headers->others['x-kolab-type'], strlen(kolab_storage_folder::KTYPE_PREFIX)));
+
+            // check object type header and abort on mismatch
+            if ($type != '*' && $object_type != $type)
+                return false;
+
+            $uid = $headers->subject;
+            $this->uid2msg[$uid] = $msguid;
+            $results[] = $uid;
+        }
+
+        return $results;
+    }
+
+
+    /**
      * Helper method to convert the given Kolab object into a dataset to be written to cache
      */
     private function _serialize($object)
diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index e4f30b7..196e677 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -324,6 +324,35 @@ class kolab_storage_folder
         if (empty($query))
             return $this->get_objects();
 
+        // synchronize caches
+        $this->cache->synchronize();
+
+        // fetch objects from cache
+        return $this->cache->select($this->_prepare_query($query));
+    }
+
+
+    /**
+     * Getter for object UIDs only
+     *
+     * @param array Pseudo-SQL query as list of filter parameter triplets
+     * @return array List of Kolab object UIDs
+     */
+    public function get_uids($query = array())
+    {
+        // synchronize caches
+        $this->cache->synchronize();
+
+        // fetch UIDs from cache
+        return $this->cache->select($this->_prepare_query($query), true);
+    }
+
+
+    /**
+     * Helper method to sanitize query arguments
+     */
+    private function _prepare_query($query)
+    {
         $type = null;
         foreach ($query as $i => $param) {
             if ($param[0] == 'type') {
@@ -338,11 +367,7 @@ class kolab_storage_folder
         if (!$type)
             $query[] = array('type','=',$this->type);
 
-        // synchronize caches
-        $this->cache->synchronize();
-
-        // fetch objects from cache
-        return $this->cache->select($query);
+        return $query;
     }
 
 


commit b8a71ce2c32bdddb63a66420ee6d29f082d2ae7e
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Jun 20 18:41:06 2012 +0200

    Get instance of rcube (not rcmail)

diff --git a/plugins/libkolab/libkolab.php b/plugins/libkolab/libkolab.php
index bff5c85..3709ee0 100644
--- a/plugins/libkolab/libkolab.php
+++ b/plugins/libkolab/libkolab.php
@@ -41,7 +41,7 @@ class libkolab extends rcube_plugin
         $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path');
         set_include_path($include_path);
 
-        $rcmail = rcmail::get_instance();
+        $rcmail = rcube::get_instance();
         try {
             kolab_format::$timezone = new DateTimeZone($rcmail->config->get('timezone', 'GMT'));
         }





More information about the commits mailing list