summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_backend.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kolab_sync_backend.php')
-rw-r--r--lib/kolab_sync_backend.php58
1 files changed, 57 insertions, 1 deletions
diff --git a/lib/kolab_sync_backend.php b/lib/kolab_sync_backend.php
index b88c984..8af2633 100644
--- a/lib/kolab_sync_backend.php
+++ b/lib/kolab_sync_backend.php
@@ -853,7 +853,7 @@ class kolab_sync_backend
if ($row = $db->fetch_assoc()) {
$synctime = $row['synctime'];
// @TODO: make sure synctime from sql is in "Y-m-d H:i:s" format
- $this->modseq[$folderid][$synctime] = json_decode($row['data']);
+ $this->modseq[$folderid][$synctime] = json_decode($row['data'], true);
}
// Cleanup: remove all records except the current one
@@ -866,6 +866,62 @@ class kolab_sync_backend
}
/**
+ * Set state of relation objects at specified point in time
+ */
+ public function relations_state_set($deviceid, $folderid, $synctime, $relations)
+ {
+ $synctime = $synctime->format('Y-m-d H:i:s');
+ $rcube = rcube::get_instance();
+ $db = $rcube->get_dbh();
+ $old_data = $this->relations[$folderid][$synctime];
+
+ if (empty($old_data)) {
+ $this->relations[$folderid][$synctime] = $relations;
+ $data = rcube_charset::clean(json_encode($relations));
+
+ $db->set_option('ignore_key_errors', true);
+ $db->query("INSERT INTO `syncroton_relations_state`"
+ ." (`device_id`, `folder_id`, `synctime`, `data`)"
+ ." VALUES (?, ?, ?, ?)",
+ $deviceid, $folderid, $synctime, $data);
+ $db->set_option('ignore_key_errors', false);
+ }
+ }
+
+ /**
+ * Get state of relation objects at specified point in time
+ */
+ public function relations_state_get($deviceid, $folderid, $synctime)
+ {
+ $synctime = $synctime->format('Y-m-d H:i:s');
+
+ if (empty($this->relations[$folderid][$synctime])) {
+ $this->relations[$folderid] = array();
+
+ $rcube = rcube::get_instance();
+ $db = $rcube->get_dbh();
+
+ $db->limitquery("SELECT `data`, `synctime` FROM `syncroton_relations_state`"
+ ." WHERE `device_id` = ? AND `folder_id` = ? AND `synctime` <= ?"
+ ." ORDER BY `synctime` DESC",
+ 0, 1, $deviceid, $folderid, $synctime);
+
+ if ($row = $db->fetch_assoc()) {
+ $synctime = $row['synctime'];
+ // @TODO: make sure synctime from sql is in "Y-m-d H:i:s" format
+ $this->relations[$folderid][$synctime] = json_decode($row['data'], true);
+ }
+
+ // Cleanup: remove all records except the current one
+ $db->query("DELETE FROM `syncroton_relations_state`"
+ ." WHERE `device_id` = ? AND `folder_id` = ? AND `synctime` <> ?",
+ $deviceid, $folderid, $synctime);
+ }
+
+ return @$this->relations[$folderid][$synctime];
+ }
+
+ /**
* Compares two arrays
*
* @param array $array1