Use a separate field for optype. No more LIKE in queries
This commit is contained in:
Родитель
a1e84804cf
Коммит
65de023e94
|
@ -147,6 +147,13 @@
|
||||||
<length>4</length>
|
<length>4</length>
|
||||||
<comments>User and time specific</comments>
|
<comments>User and time specific</comments>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>optype</name>
|
||||||
|
<type>text</type>
|
||||||
|
<notnull>false</notnull>
|
||||||
|
<length>64</length>
|
||||||
|
<comments>Operation type</comments>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>opspec</name>
|
<name>opspec</name>
|
||||||
<type>clob</type>
|
<type>clob</type>
|
||||||
|
|
|
@ -33,3 +33,17 @@ if (version_compare($installedVersion, '0.8', '<')) {
|
||||||
$query = \OC_DB::prepare('UPDATE `*PREFIX*documents_member` SET `is_guest`=1 WHERE `uid` LIKE \'%(guest)\' ');
|
$query = \OC_DB::prepare('UPDATE `*PREFIX*documents_member` SET `is_guest`=1 WHERE `uid` LIKE \'%(guest)\' ');
|
||||||
$query->execute(array());
|
$query->execute(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version_compare($installedVersion, '0.9', '<')) {
|
||||||
|
$query = \OC_DB::prepare('UPDATE `*PREFIX*documents_op` SET `optype`=? WHERE `seq`=?');
|
||||||
|
$ops = new \OCA\Documents\Db\Op();
|
||||||
|
foreach ($ops->getCollection() as $opData){
|
||||||
|
$opSpec = json_decode($opData['opspec'], true);
|
||||||
|
$query->execute(
|
||||||
|
array(
|
||||||
|
$opSpec['optype'],
|
||||||
|
$opData['seq']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
0.8.2
|
0.9.0
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Op extends \OCA\Documents\Db {
|
||||||
|
|
||||||
protected $tableName = '`*PREFIX*documents_op`';
|
protected $tableName = '`*PREFIX*documents_op`';
|
||||||
|
|
||||||
protected $insertStatement = 'INSERT INTO `*PREFIX*documents_op` (`es_id`, `member`, `opspec`) VALUES (?, ?, ?)';
|
protected $insertStatement = 'INSERT INTO `*PREFIX*documents_op` (`es_id`, `optype`, `member`, `opspec`) VALUES (?, ?, ?, ?)';
|
||||||
|
|
||||||
public static function addOpsArray($esId, $memberId, $ops){
|
public static function addOpsArray($esId, $memberId, $ops){
|
||||||
$lastSeq = "";
|
$lastSeq = "";
|
||||||
|
@ -25,6 +25,7 @@ class Op extends \OCA\Documents\Db {
|
||||||
foreach ($ops as $op) {
|
foreach ($ops as $op) {
|
||||||
$opObj->setData(array(
|
$opObj->setData(array(
|
||||||
$esId,
|
$esId,
|
||||||
|
$op['optype'],
|
||||||
$memberId,
|
$memberId,
|
||||||
json_encode($op)
|
json_encode($op)
|
||||||
));
|
));
|
||||||
|
@ -84,42 +85,73 @@ class Op extends \OCA\Documents\Db {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMember($esId, $memberId, $fullName, $color, $imageUrl){
|
public function addMember($esId, $memberId, $fullName, $color, $imageUrl){
|
||||||
$op = '{"optype":"AddMember","memberid":"'. $memberId .'","timestamp":"'. time() .'", "setProperties":{"fullName":"'. $fullName .'","color":"'. $color .'","imageUrl":"'. $imageUrl .'"}}';
|
$op = array(
|
||||||
|
'optype' => 'AddMember',
|
||||||
|
'memberid' => (string) $memberId,
|
||||||
|
'timestamp' => (string) time(),
|
||||||
|
'setProperties' => array(
|
||||||
|
'fullName' => $fullName,
|
||||||
|
'color' => $color,
|
||||||
|
'imageUrl' => $imageUrl
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->insertOp($esId, $memberId, $op);
|
$this->insertOp($esId, $memberId, $op);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeCursor($esId, $memberId){
|
public function removeCursor($esId, $memberId){
|
||||||
|
$op = array(
|
||||||
|
'optype' => 'RemoveCursor',
|
||||||
|
'memberid' => (string) $memberId,
|
||||||
|
'reason' => 'server-idle',
|
||||||
|
'timestamp' => (string) time()
|
||||||
|
);
|
||||||
if ($this->hasOp($esId, $memberId, 'AddCursor') && !$this->hasLastOp($esId, $memberId, 'RemoveCursor')){
|
if ($this->hasOp($esId, $memberId, 'AddCursor') && !$this->hasLastOp($esId, $memberId, 'RemoveCursor')){
|
||||||
$op = '{"optype":"RemoveCursor","memberid":"'. $memberId .'","reason":"server-idle","timestamp":'. time() .'}';
|
|
||||||
$this->insertOp($esId, $memberId, $op);
|
$this->insertOp($esId, $memberId, $op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMember($esId, $memberId){
|
public function removeMember($esId, $memberId){
|
||||||
|
$op = array(
|
||||||
|
'optype' => 'RemoveMember',
|
||||||
|
'memberid' => (string) $memberId,
|
||||||
|
'timestamp' => (string) time()
|
||||||
|
);
|
||||||
if ($this->hasOp($esId, $memberId, 'AddMember') && !$this->hasLastOp($esId, $memberId, 'RemoveMember')){
|
if ($this->hasOp($esId, $memberId, 'AddMember') && !$this->hasLastOp($esId, $memberId, 'RemoveMember')){
|
||||||
$op ='{"optype":"RemoveMember","memberid":"'. $memberId .'","timestamp":'. time() .'}';
|
|
||||||
$this->insertOp($esId, $memberId, $op);
|
$this->insertOp($esId, $memberId, $op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateMember($esId, $memberId, $fullName, $color, $imageUrl){
|
public function updateMember($esId, $memberId, $fullName, $color, $imageUrl){
|
||||||
//TODO: Follow the spec https://github.com/kogmbh/WebODF/blob/master/webodf/lib/ops/OpUpdateMember.js#L95
|
//TODO: Follow the spec https://github.com/kogmbh/WebODF/blob/master/webodf/lib/ops/OpUpdateMember.js#L95
|
||||||
$op = '{"optype":"UpdateMember","memberid":"'. $memberId .'","fullName":"'. $fullName .'","color":"'. $color .'","imageUrl":"'. $imageUrl .'","timestamp":'. time() .'}'
|
$op = array(
|
||||||
;
|
'optype' => 'UpdateMember',
|
||||||
|
'memberid' => (string) $memberId,
|
||||||
|
'timestamp' => (string) time(),
|
||||||
|
'fullName' => $fullName,
|
||||||
|
'color' => $color,
|
||||||
|
'imageUrl' => $imageUrl
|
||||||
|
);
|
||||||
$this->insertOp($esId, $memberId, $op);
|
$this->insertOp($esId, $memberId, $op);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function changeNick($esId, $memberId, $fullName){
|
public function changeNick($esId, $memberId, $fullName){
|
||||||
$op = '{"optype":"UpdateMember","memberid":"'. $memberId .'", "setProperties":{"fullName":"'. $fullName .'"},"timestamp":'. time() .'}'
|
$op = array(
|
||||||
;
|
'optype' => 'UpdateMember',
|
||||||
|
'memberid' => (string) $memberId,
|
||||||
|
'timestamp' => (string) time(),
|
||||||
|
'setProperties' => array(
|
||||||
|
'fullName' => $fullName,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->insertOp($esId, $memberId, $op);
|
$this->insertOp($esId, $memberId, $op);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function insertOp($esId, $memberId, $op){
|
protected function insertOp($esId, $memberId, $op){
|
||||||
$op = new Op(array(
|
$op = new Op(array(
|
||||||
$esId,
|
$esId,
|
||||||
|
$op['optype'],
|
||||||
$memberId,
|
$memberId,
|
||||||
$op
|
json_encode($op)
|
||||||
));
|
));
|
||||||
$op->insert();
|
$op->insert();
|
||||||
}
|
}
|
||||||
|
@ -130,7 +162,6 @@ class Op extends \OCA\Documents\Db {
|
||||||
FROM ' . self::DB_TABLE . '
|
FROM ' . self::DB_TABLE . '
|
||||||
WHERE `es_id`=?
|
WHERE `es_id`=?
|
||||||
AND `member`=?
|
AND `member`=?
|
||||||
|
|
||||||
ORDER BY `seq` DESC
|
ORDER BY `seq` DESC
|
||||||
',
|
',
|
||||||
2,0
|
2,0
|
||||||
|
@ -149,8 +180,9 @@ class Op extends \OCA\Documents\Db {
|
||||||
|
|
||||||
protected function hasOp($esId, $memberId, $opType){
|
protected function hasOp($esId, $memberId, $opType){
|
||||||
$ops = $this->execute(
|
$ops = $this->execute(
|
||||||
'SELECT * FROM ' . $this->tableName . ' WHERE `es_id`=? AND `opspec` LIKE \'%"' . $opType . '","memberid":"' . $memberId .'"%\'',
|
'SELECT * FROM ' . $this->tableName
|
||||||
array($esId)
|
. ' WHERE `es_id`=? AND `optype`=? AND `member`=?',
|
||||||
|
array($esId, $opType, $memberId)
|
||||||
);
|
);
|
||||||
$result = $ops->fetchAll();
|
$result = $ops->fetchAll();
|
||||||
return is_array($result) && count($result)>0;
|
return is_array($result) && count($result)>0;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче