diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-11-11 23:06:27 +0300 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-11-12 00:15:20 +0300 |
commit | 8f9b3fb867c271ef610602d423711f33d952ebeb (patch) | |
tree | e4b079f7ecc750e03b544460b61cde91aedb1077 /lib | |
parent | a1e84804cfbb3a7f90e47c19ce75d9717a334ead (diff) |
Move ops sync to a separate method
Diffstat (limited to 'lib')
-rw-r--r-- | lib/db/session.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/db/session.php b/lib/db/session.php index c951dee4..2baf3cc4 100644 --- a/lib/db/session.php +++ b/lib/db/session.php @@ -120,6 +120,41 @@ class Session extends \OCA\Documents\Db { $op->deleteBy('es_id', $esId); } + + public function syncOps($memberId, $currentHead, $clientHead, $clientOps){ + $hasOps = count($clientOps)>0; + $op = new \OCA\Documents\Db\Op(); + + // TODO handle the case ($currentHead == "") && ($seqHead != "") + if ($clientHead == $currentHead) { + // matching heads + if ($hasOps) { + // incoming ops without conflict + // Add incoming ops, respond with a new head + $newHead = \OCA\Documents\Db\Op::addOpsArray($this->getEsId(), $memberId, $clientOps); + $result = array( + 'result' => 'added', + 'head_seq' => $newHead ? $newHead : $currentHead + ); + } else { + // no incoming ops (just checking for new ops...) + $result = array( + 'result' => 'new_ops', + 'ops' => array(), + 'head_seq' => $currentHead + ); + } + } else { // HEADs do not match + $result = array( + 'result' => $hasOps ? 'conflict' : 'new_ops', + 'ops' => $op->getOpsAfterJson($this->getEsId(), $clientHead), + 'head_seq' => $currentHead, + ); + } + + return $result; + } + public function insert(){ $esId = $this->getUniqueSessionId(); array_unshift($this->data, $esId); |