3 commits - plugins/calendar plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Tue Feb 3 13:16:34 CET 2015
plugins/calendar/drivers/kolab/kolab_calendar.php | 2 -
plugins/libkolab/lib/kolab_storage.php | 5 ++
plugins/libkolab/lib/kolab_storage_cache.php | 42 ++++++++++++++++++++++
plugins/libkolab/lib/kolab_storage_folder.php | 19 +++++++++
4 files changed, 66 insertions(+), 2 deletions(-)
New commits:
commit 8dba73549d4dc4afbebb5abf229e112382e3a5b2
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Tue Feb 3 13:16:24 2015 +0100
Check new validity flag
diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index d10126a..9e3ecdf 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -76,7 +76,7 @@ class kolab_calendar extends kolab_storage_folder_api
// fetch objects from the given IMAP folder
$this->storage = kolab_storage::get_folder($this->name);
- $this->ready = $this->storage && !PEAR::isError($this->storage) && $this->storage->type !== null;
+ $this->ready = $this->storage && $this->storage->valid;
// Set readonly and alarms flags according to folder permissions
if ($this->ready) {
commit 5982ce8732a295d3050a09d1ca4c824184079b44
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Tue Feb 3 13:15:56 2015 +0100
Add error checking/reporting facilities to kolab_storage_folder instances (#4378)
diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php
index 1760939..a4868ac 100644
--- a/plugins/libkolab/lib/kolab_storage.php
+++ b/plugins/libkolab/lib/kolab_storage.php
@@ -35,6 +35,11 @@ class kolab_storage
const UID_KEY_PRIVATE = '/private/vendor/kolab/uniqueid';
const UID_KEY_CYRUS = '/shared/vendor/cmu/cyrus-imapd/uniqueid';
+ const ERROR_IMAP_CONN = 1;
+ const ERROR_CACHE_DB = 2;
+ const ERROR_NO_PERMISSION = 3;
+ const ERROR_INVALID_FOLDER = 4;
+
public static $version = '3.0';
public static $last_error;
public static $encode_ids = false;
diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index 4f12df7..134631e 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -48,6 +48,7 @@ class kolab_storage_cache
protected $extra_cols = array();
protected $order_by = null;
protected $limit = null;
+ protected $error = 0;
/**
@@ -150,6 +151,16 @@ class kolab_storage_cache
}
/**
+ * Returns code of last error
+ *
+ * @return int Error code
+ */
+ public function get_error()
+ {
+ return $this->error;
+ }
+
+ /**
* Synchronize local cache data with remote
*/
public function synchronize()
@@ -243,6 +254,7 @@ class kolab_storage_cache
}
}
+ $this->check_error();
$this->synched = time();
}
@@ -288,6 +300,7 @@ class kolab_storage_cache
}
}
+ $this->check_error();
return $this->objects[$msguid];
}
@@ -326,6 +339,8 @@ class kolab_storage_cache
// ...or set in-memory cache to false
$this->objects[$msguid] = $object;
}
+
+ $this->check_error();
}
@@ -384,6 +399,8 @@ class kolab_storage_cache
// keep a copy in memory for fast access
$this->objects = array($msguid => $object);
$this->uid2msg = array($object['uid'] => $msguid);
+
+ $this->check_error();
}
@@ -423,6 +440,7 @@ class kolab_storage_cache
}
unset($this->uid2msg[$uid]);
+ $this->check_error();
}
@@ -465,6 +483,8 @@ class kolab_storage_cache
$target->get_resource_uri(),
$this->resource_uri
);
+
+ $this->check_error();
}
/**
@@ -529,6 +549,7 @@ class kolab_storage_cache
}
if ($index->is_error()) {
+ $this->check_error();
if ($uids) {
return null;
}
@@ -551,6 +572,8 @@ class kolab_storage_cache
}
}
+ $this->check_error();
+
return $result;
}
@@ -593,6 +616,7 @@ class kolab_storage_cache
}
if ($index->is_error()) {
+ $this->check_error();
return null;
}
@@ -601,6 +625,7 @@ class kolab_storage_cache
$count = $index->count();
}
+ $this->check_error();
return $count;
}
@@ -937,6 +962,7 @@ class kolab_storage_cache
// abort if database is not set-up
if ($this->db->is_error()) {
+ $this->check_error();
$this->ready = false;
return;
}
@@ -976,6 +1002,22 @@ class kolab_storage_cache
}
/**
+ * Check IMAP connection error state
+ */
+ protected function check_error()
+ {
+ if (($err_code = $this->imap->get_error_code()) < 0) {
+ $this->error = kolab_storage::ERROR_IMAP_CONN;
+ if (($res_code = $this->imap->get_response_code()) !== 0 && in_array($res_code, array(rcube_storage::NOPERM, rcube_storage::READONLY))) {
+ $this->error = kolab_storage::ERROR_NO_PERMISSION;
+ }
+ }
+ else if ($this->db->is_error()) {
+ $this->error = kolab_storage::ERROR_CACHE_DB;
+ }
+ }
+
+ /**
* Resolve an object UID into an IMAP message UID
*
* @param string Kolab object UID
diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index 0e728a3..6c21ed4 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -36,7 +36,9 @@ class kolab_storage_folder extends kolab_storage_folder_api
*/
public $valid = false;
- private $resource_uri;
+ protected $error = 0;
+
+ protected $resource_uri;
/**
@@ -74,6 +76,10 @@ class kolab_storage_folder extends kolab_storage_folder_api
$this->id = kolab_storage::folder_id($name);
$this->valid = !empty($this->type) && $this->type != 'mail' && (!$type || $this->type == $type);
+ if (!$this->valid) {
+ $this->error = $this->imap->get_error_code() < 0 ? kolab_storage::ERROR_IMAP_CONN : kolab_storage::ERROR_INVALID_FOLDER;
+ }
+
// reset cached object properties
$this->owner = $this->namespace = $this->resource_uri = $this->info = $this->idata = null;
@@ -86,6 +92,15 @@ class kolab_storage_folder extends kolab_storage_folder_api
$this->imap->set_folder($this->name);
}
+ /**
+ * Returns code of last error
+ *
+ * @return int Error code
+ */
+ public function get_error()
+ {
+ return $this->error ?: $this->cache->get_error();
+ }
/**
* Compose a unique resource URI for this IMAP folder
commit 17cf1f489274047945762777a3d7f9e31613a4b8
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Tue Feb 3 12:31:12 2015 +0100
Update folder reference in cache (was accidentally removed in 038e269d)
diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index d9c79d5..0e728a3 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -80,6 +80,8 @@ class kolab_storage_folder extends kolab_storage_folder_api
// get a new cache instance if folder type changed
if (!$this->cache || $this->type != $oldtype)
$this->cache = kolab_storage_cache::factory($this);
+ else
+ $this->cache->set_folder($this);
$this->imap->set_folder($this->name);
}
More information about the commits
mailing list