plugins/libkolab

Aleksander Machniak machniak at kolabsys.com
Thu Jan 2 13:38:16 CET 2014


 plugins/libkolab/lib/kolab_storage_cache.php |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

New commits:
commit b1e824becf52c4ca47a044ca05b6d7fd0071d66a
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Thu Jan 2 13:37:39 2014 +0100

    Added error handling in select() and count(), so on error they will return null

diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index 3b4f825..b16bed9 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -427,6 +427,10 @@ class kolab_storage_cache
                 $this->folder_id
             );
 
+            if ($this->db->is_error($sql_result)) {
+                return null;
+            }
+
             while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
                 if ($uids) {
                     $this->uid2msg[$sql_arr['uid']] = $sql_arr['msguid'];
@@ -447,7 +451,11 @@ class kolab_storage_cache
             }
             else {  // search by object type
                 $search = 'UNDELETED HEADER X-Kolab-Type ' . kolab_format::KTYPE_PREFIX . $filter['type'];
-                $index = $this->imap->search_once($this->folder->name, $search)->get();
+                $index  = $this->imap->search_once($this->folder->name, $search)->get();
+            }
+
+            if ($index->is_error()) {
+                return null;
             }
 
             // fetch all messages in $index from IMAP
@@ -477,8 +485,6 @@ class kolab_storage_cache
      */
     public function count($query = array())
     {
-        $count = 0;
-
         // cache is in sync, we can count records in local DB
         if ($this->synched) {
             $this->_read_folder_data();
@@ -489,14 +495,23 @@ class kolab_storage_cache
                 $this->folder_id
             );
 
+            if ($this->db->is_error($sql_result)) {
+                return null;
+            }
+
             $sql_arr = $this->db->fetch_assoc($sql_result);
-            $count = intval($sql_arr['numrows']);
+            $count   = intval($sql_arr['numrows']);
         }
         else {
             // search IMAP by object type
             $filter = $this->_query2assoc($query);
             $ctype  = kolab_format::KTYPE_PREFIX . $filter['type'];
-            $index = $this->imap->search_once($this->folder->name, 'UNDELETED HEADER X-Kolab-Type ' . $ctype);
+            $index  = $this->imap->search_once($this->folder->name, 'UNDELETED HEADER X-Kolab-Type ' . $ctype);
+
+            if ($index->is_error()) {
+                return null;
+            }
+
             $count = $index->count();
         }
 




More information about the commits mailing list