summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2015-02-04 17:00:44 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2015-02-04 17:00:44 (GMT)
commit9ec1afd0a0c349a8a2c782f79ba97a84d3bcaeeb (patch)
tree2815b3f34c7f99ce8fe329cf0800cb3d3ce02d5b
parente74dd441e5c64ea4dcd2db83f39b56f9ec1d1bfa (diff)
downloadkolab-syncroton-9ec1afd0a0c349a8a2c782f79ba97a84d3bcaeeb.tar.gz
Handle kolab_storage errors correctly (#4418)
As we already found out (in #4378) kolab_storage did't prevent from sql errors if some imap connection error happened. This is already fixed, however syncroton need to use 'valid' flag implemented in kolab_storage_folder to pass correct error codes to activesync client and to prevent from more issues.
-rw-r--r--lib/kolab_sync_backend.php9
-rw-r--r--lib/kolab_sync_data.php38
2 files changed, 21 insertions, 26 deletions
diff --git a/lib/kolab_sync_backend.php b/lib/kolab_sync_backend.php
index 56a411d..a1c24a8 100644
--- a/lib/kolab_sync_backend.php
+++ b/lib/kolab_sync_backend.php
@@ -790,7 +790,7 @@ class kolab_sync_backend
// get all folders of specified type
$folderdata = $this->folder_meta();
- if (!is_array($folderdata)) {
+ if (!is_array($folderdata) || $id === null) {
return null;
}
@@ -802,10 +802,11 @@ class kolab_sync_backend
continue;
}
- $uid = self::folder_id($folder);
- $this->folder_uids[$folder] = $uid;
+ if ($uid = self::folder_id($folder)) {
+ $this->folder_uids[$folder] = $uid;
+ }
- if ($uid == $id) {
+ if ($uid === $id) {
$name = $folder;
}
}
diff --git a/lib/kolab_sync_data.php b/lib/kolab_sync_data.php
index 59bff31..ba09dd9 100644
--- a/lib/kolab_sync_data.php
+++ b/lib/kolab_sync_data.php
@@ -377,13 +377,12 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
foreach ($folders as $folderid) {
$foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
+ $folder = $this->getFolderObject($foldername);
- if ($foldername === null) {
- continue;
+ if (!$folder || !$folder->valid) {
+ throw new Syncroton_Exception_Status_ItemOperations(Syncroton_Exception_Status_ItemOperations::ITEM_SERVER_ERROR);
}
- $folder = $this->getFolderObject($foldername);
-
// Remove all entries
$folder->delete_all();
@@ -392,13 +391,12 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
$list = $this->listFolders($folderid);
foreach ($list as $folderid => $folder) {
$foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
+ $folder = $this->getFolderObject($foldername);
- if ($foldername === null) {
- continue;
+ if (!$folder || !$folder->valid) {
+ throw new Syncroton_Exception_Status_ItemOperations(Syncroton_Exception_Status_ItemOperations::ITEM_SERVER_ERROR);
}
- $folder = $this->getFolderObject($foldername);
-
// Remove all entries
$folder->delete_all();
}
@@ -545,9 +543,10 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
foreach ($folders as $folder_id) {
$foldername = $this->backend->folder_id2name($folder_id, $this->device->deviceid);
+ $folder = $this->getFolderObject($foldername);
- if ($foldername === null || !($folder = $this->getFolderObject($foldername))) {
- continue;
+ if (!$folder || !$folder->valid) {
+ throw new Syncroton_Exception_Status(Syncroton_Exception_Status::SERVER_ERROR);
}
$found++;
@@ -911,14 +910,9 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
foreach ($folders as $folderid) {
$foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
+ $folder = $this->getFolderObject($foldername);
- if ($foldername === null) {
- continue;
- }
-
- $folder = $this->getFolderObject($foldername);
-
- if ($folder && ($object = $folder->get_object($entryid))) {
+ if ($folder && $folder->valid && ($object = $folder->get_object($entryid))) {
$object['_folderid'] = $folderid;
return $object;
@@ -950,7 +944,7 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
$foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
$folder = $this->getFolderObject($foldername);
- if ($folder && $folder->save($data)) {
+ if ($folder && $folder->valid && $folder->save($data)) {
if (!empty($tags)) {
$this->setKolabTags($data['uid'], $tags);
}
@@ -975,7 +969,7 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
unset($data['categories']);
}
- if ($folder && $folder->save($data)) {
+ if ($folder && $folder->valid && $folder->save($data)) {
if (isset($tags)) {
$this->setKolabTags($data['uid'], $tags);
}
@@ -995,7 +989,7 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
if ($object) {
$folder = $this->getFolderObject($object['_mailbox']);
- if ($folder && $folder->delete($entryid)) {
+ if ($folder && $folder->valid && $folder->delete($entryid)) {
if ($this->tag_categories) {
$this->setKolabTags($object['uid'], null);
}
@@ -1078,12 +1072,12 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
*/
protected function getFolderObject($name)
{
- if ($name === null) {
+ if ($name === null || $name === '') {
return null;
}
if (!isset($this->folders[$name])) {
- $this->folders[$name] = kolab_storage::get_folder($name);
+ $this->folders[$name] = kolab_storage::get_folder($name, $this->modelName);
}
return $this->folders[$name];