Commit 7110ea18 authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage.js post method replace empty docid to an uuid

parent f1c3480d
...@@ -260,12 +260,13 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -260,12 +260,13 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.post = function (command) { that.post = function (command) {
var f = {}, doctree, revs_info, doc; var f = {}, doctree, revs_info, doc, docid;
doc = command.cloneDoc(); doc = command.cloneDoc();
docid = command.getDocId();
if (typeof doc._rev === "string" && if (typeof doc._rev === "string" &&
priv.checkRevisionFormat(doc._rev)) { priv.checkRevisionFormat(doc._rev)) {
that.error({ that.error({
"status": 30, "status": 31,
"statusText": "Wrong Revision Format", "statusText": "Wrong Revision Format",
"error": "wrong_revision_format", "error": "wrong_revision_format",
"message": "The document previous revision does not match "+ "message": "The document previous revision does not match "+
...@@ -274,6 +275,10 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -274,6 +275,10 @@ jIO.addStorageType('revision', function (spec, my) {
}); });
return; return;
} }
if (typeof docid !== "string") {
doc._id = priv.generateUuid();
docid = doc._id;
}
f.getDocumentTree = function () { f.getDocumentTree = function () {
var option = command.cloneOption(); var option = command.cloneOption();
if (option["max_retry"] === 0) { if (option["max_retry"] === 0) {
...@@ -282,7 +287,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -282,7 +287,7 @@ jIO.addStorageType('revision', function (spec, my) {
that.addJob( that.addJob(
"get", "get",
priv.substorage, priv.substorage,
command.getDocId()+priv.doctree_suffix, docid+priv.doctree_suffix,
option, option,
function (response) { function (response) {
doctree = response; doctree = response;
...@@ -303,7 +308,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -303,7 +308,7 @@ jIO.addStorageType('revision', function (spec, my) {
}; };
f.postDocument = function (doctree_update_method) { f.postDocument = function (doctree_update_method) {
revs_info = priv.postToDocumentTree(doctree, doc); revs_info = priv.postToDocumentTree(doctree, doc);
doc._id = command.getDocId()+"."+revs_info[0].rev; doc._id = docid+"."+revs_info[0].rev;
that.addJob( that.addJob(
"post", "post",
priv.substorage, priv.substorage,
...@@ -326,7 +331,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -326,7 +331,7 @@ jIO.addStorageType('revision', function (spec, my) {
); );
}; };
f.sendDocumentTree = function (method) { f.sendDocumentTree = function (method) {
doctree._id = command.getDocId()+priv.doctree_suffix; doctree._id = docid+priv.doctree_suffix;
that.addJob( that.addJob(
method, method,
priv.substorage, priv.substorage,
...@@ -335,7 +340,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -335,7 +340,7 @@ jIO.addStorageType('revision', function (spec, my) {
function (response) { function (response) {
that.success({ that.success({
"ok":true, "ok":true,
"id":command.getDocId(), "id":docid,
"rev":revs_info[0].rev "rev":revs_info[0].rev
}) })
}, function (err) { }, function (err) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment