$ops = $request->getParam('args/client_ops'); $hasOps = is_array($ops) && count($ops) > 0; $op = new Db\Op(); $currentHead = $op->getHeadSeq($esId); try { $member->updateActivity($memberId); } catch (\Exception $e) { //Db error. Not critical } // TODO handle the case ($currentHead == "") && ($seqHead != "") if ($seqHead == $currentHead) { // matching heads if ($hasOps) { // incoming ops without conflict // Add incoming ops, respond with a new head $newHead = Db\Op::addOpsArray($esId, $memberId, $ops); $response["result"] = 'added'; $response["head_seq"] = $newHead ? $newHead : $currentHead; } else { // no incoming ops (just checking for new ops...) $response["result"] = 'new_ops'; $response["ops"] = array(); $response["head_seq"] = $currentHead; } } else { // HEADs do not match $response["ops"] = $op->getOpsAfterJson($esId, $seqHead); $response["head_seq"] = $currentHead; $response["result"] = $hasOps ? 'conflict' : 'new_ops'; } $inactiveMembers = $member->updateByTimeout($esId);