pull/1/head
Victor Dubiniuk 11 years ago committed by Tobias Hintze
parent eff5bc7bb3
commit f6e1c65ea4

@ -50,10 +50,8 @@ function bogusSession($i){
return $bs; return $bs;
} }
$postbody = file_get_contents('php://input'); $request = new OCA\Office\Request();
$postobject = json_decode($postbody, true); $command = $request->getParam('command');
$command = $postobject['command'];
$response = array(); $response = array();
switch ($command){ switch ($command){
@ -64,17 +62,35 @@ switch ($command){
$response = "true"; // should fail when session is non-existent $response = "true"; // should fail when session is non-existent
break; break;
case 'sync-ops': case 'sync-ops':
// completely bogus $seqHead = $request->getParam('args/seq_head');
if (!is_null($seqHead)){
$esId = $request->getParam('args/es_id');
$memberId = $request->getParam('args/member_id');
$ops = $request->getParam('args/client_ops');
$currentHead = OCA\Office\Op::getHeadSeq($esId);
if $postobject['args']['seq_head'] is the most recent op in the ops-table: //if $postobject['args']['seq_head'] is the most recent op in the ops-table:
// append all ops in $postobject['args']['client_ops'] to the ops-table // append all ops in $postobject['args']['client_ops'] to the ops-table
else: if ($seqHead>$currentHead){
// reply with: foreach ($ops as $op){
// { OCA\Office\Op::add($op);
}
} else {
// result: 'conflict', // result: 'conflict',
// ops: a list of all ops since $postobject['args']['seq_head'] // ops: a list of all ops since $postobject['args']['seq_head']
// headSeq: the most recent op-seq // headSeq: the most recent op-seq
// } $response["result"] = 'conflict';
$response["ops"] = OCA\Office\Op::getOpsAfter($esId, $seqHead);
$last = end($response["ops"]);
$response["headSeq"] = $last['seq'];
}
} else {
// Error :)
}
/* /*
* try { * try {
* OCA\Office\Op::add( * OCA\Office\Op::add(
@ -89,9 +105,6 @@ switch ($command){
* *
* } * }
*/ */
$response['result'] = 'newOps';
$response['ops'] = array();
$response['headSeq'] = -1;
break; break;
default: default:
header('HTTP/1.1 400: BAD REQUEST'); header('HTTP/1.1 400: BAD REQUEST');

@ -4,7 +4,7 @@ namespace OCA\Office;
class Op { class Op {
public function add($op){ public static function add($op){
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_op` (`es_id`, `seq`, `member`, `opspec`) VALUES (?, ?, ?, ?) '); $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_op` (`es_id`, `seq`, `member`, `opspec`) VALUES (?, ?, ?, ?) ');
$result = $query->execute(array( $result = $query->execute(array(
$op['es_id'], $op['es_id'],
@ -12,6 +12,27 @@ class Op {
$op['member'], $op['member'],
$op['opspec'], $op['opspec'],
)); ));
return $result;
}
public static function getHeadSeq($esId){
$query = \OCP\DB::prepare('SELECT `seq` FROM `*PREFIX*office_op` WHERE `es_id`=? ORDER BY `seq` DESC LIMIT 1');
$result = $query->execute(array(
$esId
))
->fetchOne()
;
return $result;
}
public static function getOpsAfter($esId, $seq){
$query = \OCP\DB::prepare('SELECT `seq` FROM `*PREFIX*office_op` WHERE `es_id`=? AND `seq`>? ORDER BY `seq` ASC');
$result = $query->execute(array(
$esId, $seq
))
->fetchAll()
;
return $result;
} }
} }

@ -0,0 +1,27 @@
<?php
namespace OCA\Office;
class Request {
protected $data = array();
public function __construct(){
$this->data = json_decode(file_get_contents('php://input'), true);
}
public function getParam($name){
$path = explode('/', $name);
reset($path);
$index = current($path);
$param = $this->data;
do {
if (!array_key_exists($index, $param)){
return null;
}
$param = $param[$index];
} while (($index = next($path)) !== false);
return $param;
}
}
Loading…
Cancel
Save